Class DocumentReader

java.lang.Object
org.simpleframework.xml.stream.DocumentReader
All Implemented Interfaces:
EventReader

class DocumentReader extends Object implements EventReader
The DocumentReader object provides an implementation for reading XML events using DOM. This reader flattens a document in to a series of nodes, and provides these nodes as events as they are encountered. Essentially what this does is adapt the document approach to navigating the XML and provides a streaming approach. Having an implementation based on DOM ensures that the library can be used on a wider variety of platforms.
See Also:
  • Field Details

    • RESERVED

      private static final String RESERVED
      Any attribute beginning with this string has been reserved.
      See Also:
    • queue

      private NodeExtractor queue
      This is used to extract the nodes from the provided document.
    • stack

      private NodeStack stack
      This is used to keep track of which elements are in context.
    • peek

      private EventNode peek
      This is used to keep track of any events that were peeked.
  • Constructor Details

    • DocumentReader

      public DocumentReader(Document document)
      Constructor for the DocumentReader object. This makes use of a DOM document to extract events and provide them to the core framework. All nodes will be extracted from the document and queued for extraction as they are requested. This will ignore any comment nodes as they should not be considered.
      Parameters:
      document - this is the document that is to be read
  • Method Details

    • peek

      public EventNode peek() throws Exception
      This is used to peek at the node from the document. This will scan through the document, ignoring any comments to find the next relevant XML event to acquire. Typically events will be the start and end of an element, as well as any text nodes.
      Specified by:
      peek in interface EventReader
      Returns:
      this returns the next event taken from the document
      Throws:
      Exception
    • next

      public EventNode next() throws Exception
      This is used to take the next node from the document. This will scan through the document, ignoring any comments to find the next relevant XML event to acquire. Typically events will be the start and end of an element, as well as any text nodes.
      Specified by:
      next in interface EventReader
      Returns:
      this returns the next event taken from the document
      Throws:
      Exception
    • read

      private EventNode read() throws Exception
      This is used to read the next node from the document. This will scan through the document, ignoring any comments to find the next relevant XML event to acquire. Typically events will be the start and end of an element, as well as any text nodes.
      Returns:
      this returns the next event taken from the document
      Throws:
      Exception
    • read

      private EventNode read(Node node) throws Exception
      This is used to read the next node from the document. This will scan through the document, ignoring any comments to find the next relevant XML event to acquire. Typically events will be the start and end of an element, as well as any text nodes.
      Parameters:
      node - this is the XML node that has been read
      Returns:
      this returns the next event taken from the document
      Throws:
      Exception
    • convert

      private EventNode convert(Node node) throws Exception
      This is used to convert the provided node in to an event. The conversion process ensures the node can be digested by the core reader and used to provide an InputNode that can be used to represent the XML elements or attributes. If the provided node is not an element then it is considered text.
      Parameters:
      node - the node that is to be converted to an event
      Returns:
      this returns an event created from the given node
      Throws:
      Exception
    • start

      private DocumentReader.Start start(Node node)
      This is used to convert the provided node to a start event. The conversion process ensures the node can be digested by the core reader and used to provide an InputNode that can be used to represent an XML elements within the source document.
      Parameters:
      node - the node that is to be converted to a start event
      Returns:
      this returns a start event created from the given node
    • build

      This is used to build the attributes that are to be used to populate the start event. Populating the start event with the attributes it contains is required so that each element will contain its associated attributes. Only attributes that are not reserved will be added to the start event.
      Parameters:
      event - this is the start event that is to be populated
      Returns:
      this returns a start event with its attributes
    • attribute

      private DocumentReader.Entry attribute(Node node)
      This is used to convert the provided node to an attribute. The conversion process ensures the node can be digested by the core reader and used to provide an InputNode that can be used to represent an XML attribute within the source document.
      Parameters:
      node - the node that is to be converted to an attribute
      Returns:
      this returns an attribute created from the given node
    • text

      private DocumentReader.Text text(Node node)
      This is used to convert the provided node to a text event. The conversion process ensures the node can be digested by the core reader and used to provide an InputNode that can be used to represent an XML attribute within the source document.
      Parameters:
      node - the node that is to be converted to a text event
      Returns:
      this returns the text event created from the given node
    • end

      private DocumentReader.End end()
      This is used to create a node event to signify that an element has just ended. End events are important as they allow the core reader to determine if a node is still in context. This provides a more convenient way to use InputNode objects as they should only ever be able to extract their children.
      Returns:
      this returns an end event to signify an element close