public class JRXmlDataSource extends JRAbstractTextDataSource implements JRRewindableDataSource
The data source is constructed around a node set (record set) selected by an XPath expression from the xml document.
Each field can provide an additional XPath expresion that will be used to select its value. This expression must be specified using the "fieldDescription" element of the field. The expression is evaluated in the context of the current node thus the expression should be relative to the current node.
To support subreports, sub data sources can be created. There are two different methods for creating sub data sources. The first one allows to create a sub data source rooted at the current node. The current node can be seen as a new document around which the sub data source is created. The second method allows to create a sub data source that is rooted at the same document that is used by the data source but uses a different XPath select expression.
Example:
<A>
<B id="0">
<C>
<C>
</B>
<B id="1">
<C>
<C>
</B>
<D id="3">
<E>
<E>
</D>
</A>
Data source creation
Generally the full power of XPath expression is available. As an example, "/A/B[@id > 0"] will select all the nodes of type /A/B having the id greater than 0. You'll find a short XPath tutorial here.
Note on performance. Due to the fact that all the XPath expression are interpreted the data source performance is not great. For the cases where more speed is required, consider implementing a custom data source that directly accesses the Document through the DOM API.
JRXPathExecuterUtilsEXCEPTION_MESSAGE_KEY_CANNOT_CONVERT_FIELD_TYPE, EXCEPTION_MESSAGE_KEY_CANNOT_MODIFY_PROPERTIES_AFTER_START, EXCEPTION_MESSAGE_KEY_NODE_NOT_AVAILABLE, EXCEPTION_MESSAGE_KEY_NULL_DOCUMENT, EXCEPTION_MESSAGE_KEY_NULL_SELECT_EXPRESSION, EXCEPTION_MESSAGE_KEY_UNKNOWN_COLUMN_NAME, EXCEPTION_MESSAGE_KEY_UNKNOWN_NUMBER_TYPE| Constructor and Description |
|---|
JRXmlDataSource(Document document) |
JRXmlDataSource(Document document,
String selectExpression) |
JRXmlDataSource(File file) |
JRXmlDataSource(File file,
boolean isNamespaceAware) |
JRXmlDataSource(File file,
String selectExpression) |
JRXmlDataSource(File file,
String selectExpression,
boolean isNamespaceAware) |
JRXmlDataSource(InputStream in) |
JRXmlDataSource(InputStream in,
boolean isNamespaceAware) |
JRXmlDataSource(InputStream in,
String selectExpression) |
JRXmlDataSource(InputStream in,
String selectExpression,
boolean isNamespaceAware) |
JRXmlDataSource(JasperReportsContext jasperReportsContext,
Document document)
Creates the data source by parsing the xml document from the given file.
|
JRXmlDataSource(JasperReportsContext jasperReportsContext,
Document document,
String selectExpression)
Creates the data source by parsing the xml document from the given file.
|
JRXmlDataSource(JasperReportsContext jasperReportsContext,
File file)
Creates the data source by parsing the xml document from the given file.
|
JRXmlDataSource(JasperReportsContext jasperReportsContext,
File file,
boolean isNamespaceAware) |
JRXmlDataSource(JasperReportsContext jasperReportsContext,
File file,
String selectExpression)
Creates the data source by parsing the xml document from the given file.
|
JRXmlDataSource(JasperReportsContext jasperReportsContext,
File file,
String selectExpression,
boolean isNamespaceAware) |
JRXmlDataSource(JasperReportsContext jasperReportsContext,
InputStream in)
Creates the data source by parsing the xml document from the given input stream.
|
JRXmlDataSource(JasperReportsContext jasperReportsContext,
InputStream in,
boolean isNamespaceAware) |
JRXmlDataSource(JasperReportsContext jasperReportsContext,
InputStream in,
String selectExpression)
Creates the data source by parsing the xml document from the given input stream.
|
JRXmlDataSource(JasperReportsContext jasperReportsContext,
InputStream in,
String selectExpression,
boolean isNamespaceAware) |
JRXmlDataSource(JasperReportsContext jasperReportsContext,
String uri)
Creates the data source by parsing the xml document from the given system identifier (URI).
|
JRXmlDataSource(JasperReportsContext jasperReportsContext,
String uri,
boolean isNamespaceAware) |
JRXmlDataSource(JasperReportsContext jasperReportsContext,
String uri,
String selectExpression)
Creates the data source by parsing the xml document from the given system identifier (URI).
|
JRXmlDataSource(JasperReportsContext jasperReportsContext,
String uri,
String selectExpression,
boolean isNamespaceAware) |
JRXmlDataSource(String uri) |
JRXmlDataSource(String uri,
boolean isNamespaceAware) |
JRXmlDataSource(String uri,
String selectExpression) |
JRXmlDataSource(String uri,
String selectExpression,
boolean isNamespaceAware) |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the reader.
|
JRXmlDataSource |
dataSource()
Creates a sub data source using as root document the document used by "this" data source.
|
JRXmlDataSource |
dataSource(String selectExpr)
Creates a sub data source using as root document the document used by "this" data source.
|
Object |
getFieldValue(JRField jrField)
Gets the field value for the current position.
|
String |
getText(Node node)
Return the text that a node contains.
|
void |
moveFirst()
Moves back to the first element in the data source.
|
boolean |
next()
Tries to position the cursor on the next element in the data source.
|
JRXmlDataSource |
subDataSource()
Creates a sub data source using the current node (record) as the root
of the document.
|
JRXmlDataSource |
subDataSource(String selectExpr)
Creates a sub data source using the current node (record) as the root
of the document.
|
Document |
subDocument()
Creates a document using the current node as root.
|
convertNumber, convertStringValue, getConvertBean, getDatePattern, getFormattedDate, getFormattedNumber, getLocale, getNumberPattern, getTextAttributes, getTimeZone, setDatePattern, setLocale, setLocale, setNumberPattern, setTextAttributes, setTextAttributes, setTimeZone, setTimeZonepublic JRXmlDataSource(JasperReportsContext jasperReportsContext, Document document) throws JRException
document - the documentJRException - if the data source cannot be createdpublic JRXmlDataSource(Document document) throws JRException
JRExceptionJRXmlDataSource(JasperReportsContext, Document)public JRXmlDataSource(JasperReportsContext jasperReportsContext, Document document, String selectExpression) throws JRException
document - the documentselectExpression - the XPath select expressionJRException - if the data source cannot be createdpublic JRXmlDataSource(Document document, String selectExpression) throws JRException
JRExceptionJRXmlDataSource(JasperReportsContext, Document, String)public JRXmlDataSource(JasperReportsContext jasperReportsContext, InputStream in) throws JRException
in - the input streamJRExceptionJRXmlDataSource(Document)public JRXmlDataSource(JasperReportsContext jasperReportsContext, InputStream in, boolean isNamespaceAware) throws JRException
JRExceptionpublic JRXmlDataSource(InputStream in) throws JRException
JRExceptionJRXmlDataSource(JasperReportsContext, InputStream)public JRXmlDataSource(InputStream in, boolean isNamespaceAware) throws JRException
JRExceptionpublic JRXmlDataSource(JasperReportsContext jasperReportsContext, InputStream in, String selectExpression) throws JRException
JRExceptionJRXmlDataSource(InputStream),
JRXmlDataSource(Document, String)public JRXmlDataSource(JasperReportsContext jasperReportsContext, InputStream in, String selectExpression, boolean isNamespaceAware) throws JRException
JRExceptionpublic JRXmlDataSource(InputStream in, String selectExpression) throws JRException
JRExceptionJRXmlDataSource(JasperReportsContext, InputStream, String)public JRXmlDataSource(InputStream in, String selectExpression, boolean isNamespaceAware) throws JRException
JRExceptionpublic JRXmlDataSource(JasperReportsContext jasperReportsContext, String uri) throws JRException
If the system identifier is a URL, it must be full resolved.
uri - the system identifierJRExceptionJRXmlDataSource(Document)public JRXmlDataSource(JasperReportsContext jasperReportsContext, String uri, boolean isNamespaceAware) throws JRException
JRExceptionpublic JRXmlDataSource(String uri) throws JRException
JRExceptionJRXmlDataSource(JasperReportsContext, String)public JRXmlDataSource(String uri, boolean isNamespaceAware) throws JRException
JRExceptionpublic JRXmlDataSource(JasperReportsContext jasperReportsContext, String uri, String selectExpression) throws JRException
JRExceptionJRXmlDataSource(String),
JRXmlDataSource(Document, String)public JRXmlDataSource(JasperReportsContext jasperReportsContext, String uri, String selectExpression, boolean isNamespaceAware) throws JRException
JRExceptionpublic JRXmlDataSource(String uri, String selectExpression) throws JRException
JRExceptionJRXmlDataSource(JasperReportsContext, String, String)public JRXmlDataSource(String uri, String selectExpression, boolean isNamespaceAware) throws JRException
JRExceptionpublic JRXmlDataSource(JasperReportsContext jasperReportsContext, File file) throws JRException
file - the fileJRExceptionJRXmlDataSource(Document)public JRXmlDataSource(JasperReportsContext jasperReportsContext, File file, boolean isNamespaceAware) throws JRException
JRExceptionpublic JRXmlDataSource(File file) throws JRException
JRExceptionJRXmlDataSource(JasperReportsContext, File)public JRXmlDataSource(File file, boolean isNamespaceAware) throws JRException
JRExceptionpublic JRXmlDataSource(JasperReportsContext jasperReportsContext, File file, String selectExpression) throws JRException
JRExceptionJRXmlDataSource(File),
JRXmlDataSource(Document, String)public JRXmlDataSource(JasperReportsContext jasperReportsContext, File file, String selectExpression, boolean isNamespaceAware) throws JRException
JRExceptionpublic JRXmlDataSource(File file, String selectExpression) throws JRException
JRExceptionJRXmlDataSource(JasperReportsContext, File, String)public JRXmlDataSource(File file, String selectExpression, boolean isNamespaceAware) throws JRException
JRExceptionpublic void moveFirst()
throws JRException
JRRewindableDataSourcemoveFirst in interface JRRewindableDataSourceJRExceptionpublic boolean next()
JRDataSourcenext in interface JRDataSourcepublic Object getFieldValue(JRField jrField) throws JRException
JRDataSourcegetFieldValue in interface JRDataSourceJRExceptionpublic JRXmlDataSource subDataSource(String selectExpr) throws JRException
selectExpr - the XPath select expressionJRException - if the sub data source couldn't be createdJRXmlDataSource(Document, String)public JRXmlDataSource subDataSource() throws JRException
JRException - if the data source cannot be createdsubDataSource(String),
JRXmlDataSource(Document)public Document subDocument() throws JRException
JRExceptionpublic JRXmlDataSource dataSource(String selectExpr) throws JRException
selectExpr - the XPath select expressionJRException - if the sub data source couldn't be createdJRXmlDataSource(Document, String)public JRXmlDataSource dataSource() throws JRException
JRException - if the data source cannot be createddataSource(String),
JRXmlDataSource(Document)public String getText(Node node)
node - a DOM nodepublic void close()
Copyright © 2017. All rights reserved.