BeanIO 1.2.3

org.beanio.stream.xml
Class XmlReader

java.lang.Object
  extended by org.beanio.stream.xml.XmlReader
All Implemented Interfaces:
RecordReader

public class XmlReader
extends Object
implements RecordReader

A XmlReader is 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). A XmlReader is 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 XmlReader makes use of the DOM user data feature to pass additional information to and from the parser. The GROUP_COUNT is an Integer value added to elements in the base document to indicate the number of times an element was read from the input stream. And the IS_NAMESPACE_IGNORED is a Boolean value 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
Author:
Kevin Seim

Field Summary
static String GROUP_COUNT
          The DOM user data key to obtain the number of times a group element was read in the base document as a java.lang.Integer.
static 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.
 
Constructor Summary
XmlReader(Reader reader)
          Constructs a new XmlReader.
XmlReader(Reader reader, Document base)
          Constructs a new XmlReader.
 
Method Summary
 void close()
          Closes this input stream.
 int getRecordLineNumber()
          Returns the line number of the last record from this input stream.
 String getRecordText()
          Returns the unparsed record text of the last record read.
 Document read()
          Reads a single record from this input stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GROUP_COUNT

public static final String GROUP_COUNT
The DOM user data key to obtain the number of times a group element was read in the base document as a java.lang.Integer.

See Also:
Constant Field Values

IS_NAMESPACE_IGNORED

public static final 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 a java.lang.Boolean.

See Also:
Constant Field Values
Constructor Detail

XmlReader

public XmlReader(Reader reader)
Constructs a new XmlReader.

Parameters:
reader - the input stream to read from

XmlReader

public XmlReader(Reader reader,
                 Document base)
Constructs a new XmlReader.

Parameters:
reader - the input stream to read from
base - the base document object model (DOM) that defines the group structure of the XML. May be null if fully reading the XML document.
Method Detail

read

public Document read()
              throws IOException,
                     RecordIOException
Description copied from interface: RecordReader
Reads a single record from this input stream. The type of object returned depends on the format of the stream.

Specified by:
read in interface RecordReader
Returns:
the record value, or null if the end of the stream was reached.
Throws:
IOException - if an I/O error occurs reading from the stream
RecordIOException - if the record is malformed and cannot be parsed, but subsequent reads may still be possible

close

public void close()
           throws IOException
Description copied from interface: RecordReader
Closes this input stream.

Specified by:
close in interface RecordReader
Throws:
IOException - if an I/O error occurs closing the stream

getRecordLineNumber

public int getRecordLineNumber()
Description copied from interface: RecordReader
Returns 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:
getRecordLineNumber in interface RecordReader
Returns:
the beginning line number of the last record read

getRecordText

public String getRecordText()
Description copied from interface: RecordReader
Returns the unparsed record text of the last record read.

Specified by:
getRecordText in interface RecordReader
Returns:
the unparsed text of the last record read

BeanIO 1.2.3

Copyright © 2010-2012 Kevin Seim