Class NodeReader

java.lang.Object
org.simpleframework.xml.stream.NodeReader

class NodeReader extends Object
The NodeReader object is used to read elements from the specified XML event reader. This reads input node objects that represent elements within the source XML document. This will allow details to be read using input node objects, as long as the end elements for those input nodes have not been ended.

For example, if an input node represented the root element of a document then that input node could read all elements within the document. However, if the input node represented a child element then it would only be able to read its children.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final EventReader
    Represents the XML event reader used to read all elements.
    private final InputStack
    This stack enables the reader to keep track of elements.
    private final StringBuilder
    This is used to collect the text between the element tags.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor for the NodeReader object.
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    Read the contents of the characters between the specified XML element tags, if the read is currently at that element.
    boolean
    This is used to determine if this input node is empty.
    private boolean
    isName(EventNode node, String name)
    This is used to determine the name of the node specified.
    boolean
    This method is used to determine if this node is the root node for the XML document.
    private String
    This is used to read the text between element tags.
    Returns the next input node from the XML document, if it is a child element of the specified input node.
    Returns the next input node from the XML document, if it is a child element of the specified input node.
    Returns the root input node for the document.
    private InputNode
    This is used to convert the start element to an input node.
    private String
    Read the contents of the characters between the specified XML element tags, if the read is currently at that element.
    Read the contents of the characters between the specified XML element tags, if the read is currently at that element.
    void
    This method is used to skip an element within the XML document.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • text

      private final StringBuilder text
      This is used to collect the text between the element tags.
    • reader

      private final EventReader reader
      Represents the XML event reader used to read all elements.
    • stack

      private final InputStack stack
      This stack enables the reader to keep track of elements.
  • Constructor Details

    • NodeReader

      public NodeReader(EventReader reader)
      Constructor for the NodeReader object. This is used to read XML events a input node objects from the event reader.
      Parameters:
      reader - this is the event reader for the XML document
  • Method Details

    • isRoot

      public boolean isRoot(InputNode node)
      This method is used to determine if this node is the root node for the XML document. The root node is the first node in the document and has no sibling nodes. This is false if the node has a parent node or a sibling node.
      Returns:
      true if this is the root node within the document
    • readRoot

      public InputNode readRoot() throws Exception
      Returns the root input node for the document. This is returned only if no other elements have been read. Once the root element has been read from the event reader this will return null.
      Returns:
      this returns the root input node for the document
      Throws:
      Exception
    • readElement

      public InputNode readElement(InputNode from) throws Exception
      Returns the next input node from the XML document, if it is a child element of the specified input node. This essentially determines whether the end tag has been read for the specified node, if so then null is returned. If however the specified node has not had its end tag read then this returns the next element, if that element is a child of the that node.
      Parameters:
      from - this is the input node to read with
      Returns:
      this returns the next input node from the document
      Throws:
      Exception
    • readElement

      public InputNode readElement(InputNode from, String name) throws Exception
      Returns the next input node from the XML document, if it is a child element of the specified input node. This essentially the same as the readElement(InputNode) object except that this will not read the element if it does not have the name specified. This essentially acts as a peak function.
      Parameters:
      from - this is the input node to read with
      name - this is the name expected from the next element
      Returns:
      this returns the next input node from the document
      Throws:
      Exception
    • readStart

      private InputNode readStart(InputNode from, EventNode event) throws Exception
      This is used to convert the start element to an input node. This will push the created input node on to the stack. The input node created contains a reference to this reader. so that it can be used to read child elements and values.
      Parameters:
      from - this is the parent element for the start event
      event - this is the start element to be wrapped
      Returns:
      this returns an input node for the given element
      Throws:
      Exception
    • isName

      private boolean isName(EventNode node, String name)
      This is used to determine the name of the node specified. The name of the node is determined to be the name of the element if that element is converts to a valid StAX start element.
      Parameters:
      node - this is the StAX node to acquire the name from
      name - this is the name of the node to check against
      Returns:
      true if the specified node has the given local name
    • readValue

      public String readValue(InputNode from) throws Exception
      Read the contents of the characters between the specified XML element tags, if the read is currently at that element. This allows characters associated with the element to be used. If the specified node is not the current node, null is returned.
      Parameters:
      from - this is the input node to read the value from
      Returns:
      this returns the characters from the specified node
      Throws:
      Exception
    • readText

      private String readText(InputNode from) throws Exception
      Read the contents of the characters between the specified XML element tags, if the read is currently at that element. This allows characters associated with the element to be used. If the specified node is not the current node, null is returned.
      Parameters:
      from - this is the input node to read the value from
      Returns:
      this returns the characters from the specified node
      Throws:
      Exception
    • readBuffer

      private String readBuffer(InputNode from) throws Exception
      This is used to read the text between element tags. If there is any text held in the buffer then this will return that text and clear the buffer. Clearing the buffer in this way means that the text can only ever be read once.
      Parameters:
      from - this is the node to read the text from
      Returns:
      this returns the string within the buffer if any
      Throws:
      Exception
    • fillText

      private void fillText(InputNode from) throws Exception
      Read the contents of the characters between the specified XML element tags, if the read is currently at that element. This allows characters associated with the element to be used. If the specified node is not the current node, null is returned.
      Parameters:
      from - this is the input node to read the value from
      Throws:
      Exception
    • isEmpty

      public boolean isEmpty(InputNode from) throws Exception
      This is used to determine if this input node is empty. An empty node is one with no attributes or children. This can be used to determine if a given node represents an empty entity, with which no extra data can be extracted.
      Parameters:
      from - this is the input node to read the value from
      Returns:
      this returns true if the node is an empty element
      Throws:
      Exception - thrown if there was a parse error
    • skipElement

      public void skipElement(InputNode from) throws Exception
      This method is used to skip an element within the XML document. This will simply read each element from the document until the specified element is at the top of the stack. When the specified element is at the top of the stack this returns.
      Parameters:
      from - this is the element to skip from the XML document
      Throws:
      Exception