Package org.simpleframework.xml.stream
Class DocumentReader
java.lang.Object
org.simpleframework.xml.stream.DocumentReader
- All Implemented Interfaces:
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
TheEnd
object is used to represent the end of an element.private static class
TheEntry
object is used to represent an attribute within a start element.private static class
TheStart
object is used to represent the start of an XML element.private static class
TheText
object is used to represent a text event. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate EventNode
This is used to keep track of any events that were peeked.private NodeExtractor
This is used to extract the nodes from the provided document.private static final String
Any attribute beginning with this string has been reserved.private NodeStack
This is used to keep track of which elements are in context. -
Constructor Summary
ConstructorsConstructorDescriptionDocumentReader
(Document document) Constructor for theDocumentReader
object. -
Method Summary
Modifier and TypeMethodDescriptionprivate DocumentReader.Entry
This is used to convert the provided node to an attribute.private DocumentReader.Start
build
(DocumentReader.Start event) This is used to build the attributes that are to be used to populate the start event.private EventNode
This is used to convert the provided node in to an event.private DocumentReader.End
end()
This is used to create a node event to signify that an element has just ended.next()
This is used to take the next node from the document.peek()
This is used to peek at the node from the document.private EventNode
read()
This is used to read the next node from the document.private EventNode
This is used to read the next node from the document.private DocumentReader.Start
This is used to convert the provided node to a start event.private DocumentReader.Text
This is used to convert the provided node to a text event.
-
Field Details
-
RESERVED
Any attribute beginning with this string has been reserved.- See Also:
-
queue
This is used to extract the nodes from the provided document. -
stack
This is used to keep track of which elements are in context. -
peek
This is used to keep track of any events that were peeked.
-
-
Constructor Details
-
DocumentReader
Constructor for theDocumentReader
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
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 interfaceEventReader
- Returns:
- this returns the next event taken from the document
- Throws:
Exception
-
next
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 interfaceEventReader
- Returns:
- this returns the next event taken from the document
- Throws:
Exception
-
read
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
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
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 anInputNode
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
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 anInputNode
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
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 anInputNode
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
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 anInputNode
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
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 useInputNode
objects as they should only ever be able to extract their children.- Returns:
- this returns an end event to signify an element close
-