Package org.simpleframework.xml.stream
Class NodeReader
- java.lang.Object
-
- org.simpleframework.xml.stream.NodeReader
-
class NodeReader extends java.lang.Object
TheNodeReader
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 EventReader
reader
Represents the XML event reader used to read all elements.private InputStack
stack
This stack enables the reader to keep track of elements.private java.lang.StringBuilder
text
This is used to collect the text between the element tags.
-
Constructor Summary
Constructors Constructor Description NodeReader(EventReader reader)
Constructor for theNodeReader
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
fillText(InputNode from)
Read the contents of the characters between the specified XML element tags, if the read is currently at that element.boolean
isEmpty(InputNode from)
This is used to determine if this input node is empty.private boolean
isName(EventNode node, java.lang.String name)
This is used to determine the name of the node specified.boolean
isRoot(InputNode node)
This method is used to determine if this node is the root node for the XML document.private java.lang.String
readBuffer(InputNode from)
This is used to read the text between element tags.InputNode
readElement(InputNode from)
Returns the next input node from the XML document, if it is a child element of the specified input node.InputNode
readElement(InputNode from, java.lang.String name)
Returns the next input node from the XML document, if it is a child element of the specified input node.InputNode
readRoot()
Returns the root input node for the document.private InputNode
readStart(InputNode from, EventNode event)
This is used to convert the start element to an input node.private java.lang.String
readText(InputNode from)
Read the contents of the characters between the specified XML element tags, if the read is currently at that element.java.lang.String
readValue(InputNode from)
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 Detail
-
text
private final java.lang.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 Detail
-
NodeReader
public NodeReader(EventReader reader)
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 Detail
-
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 java.lang.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:
java.lang.Exception
-
readElement
public InputNode readElement(InputNode from) throws java.lang.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:
java.lang.Exception
-
readElement
public InputNode readElement(InputNode from, java.lang.String name) throws java.lang.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 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:
java.lang.Exception
-
readStart
private InputNode readStart(InputNode from, EventNode event) throws java.lang.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 eventevent
- this is the start element to be wrapped- Returns:
- this returns an input node for the given element
- Throws:
java.lang.Exception
-
isName
private boolean isName(EventNode node, java.lang.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 fromname
- this is the name of the node to check against- Returns:
- true if the specified node has the given local name
-
readValue
public java.lang.String readValue(InputNode from) throws java.lang.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:
java.lang.Exception
-
readText
private java.lang.String readText(InputNode from) throws java.lang.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:
java.lang.Exception
-
readBuffer
private java.lang.String readBuffer(InputNode from) throws java.lang.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:
java.lang.Exception
-
fillText
private void fillText(InputNode from) throws java.lang.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:
java.lang.Exception
-
isEmpty
public boolean isEmpty(InputNode from) throws java.lang.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:
java.lang.Exception
- thrown if there was a parse error
-
skipElement
public void skipElement(InputNode from) throws java.lang.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:
java.lang.Exception
-
-