Package org.beanio.stream.xml
Class XmlReader
- java.lang.Object
-
- org.beanio.stream.xml.XmlReader
-
- All Implemented Interfaces:
RecordReader
public class XmlReader extends java.lang.Object implements RecordReader
AXmlReaderis used to read records from a XML input stream. Each XML record read from the input stream is parsed into a Document Object Model (DOM). AXmlReaderis configured using a base DOM object to define the group structure of the XML. When a XML element is read from the input stream that is not found in the base document, the element and its children are appended to the base document to form the record. The base document object model will be modified as the input stream is read and should therefore not be shared across multiple streams.A
XmlReadermakes use of the DOM user data feature to pass additional information to and from the parser. TheGROUP_COUNTis anIntegervalue added to elements in the base document to indicate the number of times an element was read from the input stream. And theIS_NAMESPACE_IGNOREDis aBooleanvalue set on elements in the base document where the XML namespace should not be used to match nodes read from the input stream.The method
getRecordText()is not currently supported.- Since:
- 1.1
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringGROUP_COUNTThe DOM user data key to obtain the number of times a group element was read in the base document as ajava.lang.Integer.static java.lang.StringIS_NAMESPACE_IGNOREDThe DOM user data key to indicate whether the namespace of an element in the base document is ignored when matching nodes read from an input stream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes this input stream.intgetRecordLineNumber()Returns the line number of the last record from this input stream.java.lang.StringgetRecordText()Returns the unparsed record text of the last record read.org.w3c.dom.Documentread()Reads a single record from this input stream.
-
-
-
Field Detail
-
GROUP_COUNT
public static final java.lang.String GROUP_COUNT
The DOM user data key to obtain the number of times a group element was read in the base document as ajava.lang.Integer.- See Also:
- Constant Field Values
-
IS_NAMESPACE_IGNORED
public static final java.lang.String IS_NAMESPACE_IGNORED
The DOM user data key to indicate whether the namespace of an element in the base document is ignored when matching nodes read from an input stream. The value must be ajava.lang.Boolean.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
XmlReader
public XmlReader(java.io.Reader reader)
Constructs a newXmlReader.- Parameters:
reader- the input stream to read from
-
XmlReader
public XmlReader(java.io.Reader reader, org.w3c.dom.Document base)Constructs a newXmlReader.- Parameters:
reader- the input stream to read frombase- the base document object model (DOM) that defines the group structure of the XML. May benullif fully reading the XML document.
-
-
Method Detail
-
read
public org.w3c.dom.Document read() throws java.io.IOException, RecordIOExceptionDescription copied from interface:RecordReaderReads a single record from this input stream. The type of object returned depends on the format of the stream.- Specified by:
readin interfaceRecordReader- Returns:
- the record value, or null if the end of the stream was reached.
- Throws:
java.io.IOException- if an I/O error occurs reading from the streamRecordIOException- if the record is malformed and cannot be parsed, but subsequent reads may still be possible
-
close
public void close() throws java.io.IOExceptionDescription copied from interface:RecordReaderCloses this input stream.- Specified by:
closein interfaceRecordReader- Throws:
java.io.IOException- if an I/O error occurs closing the stream
-
getRecordLineNumber
public int getRecordLineNumber()
Description copied from interface:RecordReaderReturns the line number of the last record from this input stream. If a record spans multiple lines, the line number at the beginning of the record is returned. May return -1 if the end of the stream was reached, or 0 if new lines are not used to terminate records.- Specified by:
getRecordLineNumberin interfaceRecordReader- Returns:
- the beginning line number of the last record read
-
getRecordText
public java.lang.String getRecordText()
Description copied from interface:RecordReaderReturns the unparsed record text of the last record read.- Specified by:
getRecordTextin interfaceRecordReader- Returns:
- the unparsed text of the last record read
-
-