Package org.simpleframework.xml.stream
Class NodeReader
java.lang.Object
org.simpleframework.xml.stream.NodeReader
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
FieldsModifier and TypeFieldDescriptionprivate 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 -
Method Summary
Modifier and TypeMethodDescriptionprivate 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
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
readBuffer
(InputNode from) This is used to read the text between element tags.readElement
(InputNode from) Returns the next input node from the XML document, if it is a child element of the specified input node.readElement
(InputNode from, String name) Returns the next input node from the XML document, if it is a child element of the specified input node.readRoot()
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
skipElement
(InputNode from) This method is used to skip an element within the XML document.
-
Field Details
-
text
This is used to collect the text between the element tags. -
reader
Represents the XML event reader used to read all elements. -
stack
This stack enables the reader to keep track of elements.
-
-
Constructor Details
-
NodeReader
Constructor for theNodeReader
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
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
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
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
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 thereadElement(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 withname
- this is the name expected from the next element- Returns:
- this returns the next input node from the document
- Throws:
Exception
-
readStart
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 eventevent
- this is the start element to be wrapped- Returns:
- this returns an input node for the given element
- Throws:
Exception
-
isName
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 fromname
- this is the name of the node to check against- Returns:
- true if the specified node has the given local name
-
readValue
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
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
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
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
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
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
-