Package org.simpleframework.xml.stream
Class DocumentReader
- java.lang.Object
-
- org.simpleframework.xml.stream.DocumentReader
-
- All Implemented Interfaces:
EventReader
class DocumentReader extends java.lang.Object implements EventReader
TheDocumentReaderobject 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:
DocumentProvider
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classDocumentReader.EndTheEndobject is used to represent the end of an element.private static classDocumentReader.EntryTheEntryobject is used to represent an attribute within a start element.private static classDocumentReader.StartTheStartobject is used to represent the start of an XML element.private static classDocumentReader.TextTheTextobject is used to represent a text event.
-
Field Summary
Fields Modifier and Type Field Description private EventNodepeekThis is used to keep track of any events that were peeked.private NodeExtractorqueueThis is used to extract the nodes from the provided document.private static java.lang.StringRESERVEDAny attribute beginning with this string has been reserved.private NodeStackstackThis is used to keep track of which elements are in context.
-
Constructor Summary
Constructors Constructor Description DocumentReader(org.w3c.dom.Document document)Constructor for theDocumentReaderobject.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private DocumentReader.Entryattribute(org.w3c.dom.Node node)This is used to convert the provided node to an attribute.private DocumentReader.Startbuild(DocumentReader.Start event)This is used to build the attributes that are to be used to populate the start event.private EventNodeconvert(org.w3c.dom.Node node)This is used to convert the provided node in to an event.private DocumentReader.Endend()This is used to create a node event to signify that an element has just ended.EventNodenext()This is used to take the next node from the document.EventNodepeek()This is used to peek at the node from the document.private EventNoderead()This is used to read the next node from the document.private EventNoderead(org.w3c.dom.Node node)This is used to read the next node from the document.private DocumentReader.Startstart(org.w3c.dom.Node node)This is used to convert the provided node to a start event.private DocumentReader.Texttext(org.w3c.dom.Node node)This is used to convert the provided node to a text event.
-
-
-
Field Detail
-
RESERVED
private static final java.lang.String RESERVED
Any attribute beginning with this string has been reserved.- See Also:
- Constant Field Values
-
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 Detail
-
DocumentReader
public DocumentReader(org.w3c.dom.Document document)
Constructor for theDocumentReaderobject. 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 Detail
-
peek
public EventNode peek() throws java.lang.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:
peekin interfaceEventReader- Returns:
- this returns the next event taken from the document
- Throws:
java.lang.Exception
-
next
public EventNode next() throws java.lang.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:
nextin interfaceEventReader- Returns:
- this returns the next event taken from the document
- Throws:
java.lang.Exception
-
read
private EventNode read() throws java.lang.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:
java.lang.Exception
-
read
private EventNode read(org.w3c.dom.Node node) throws java.lang.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:
java.lang.Exception
-
convert
private EventNode convert(org.w3c.dom.Node node) throws java.lang.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 anInputNodethat 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:
java.lang.Exception
-
start
private DocumentReader.Start start(org.w3c.dom.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 anInputNodethat 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
private DocumentReader.Start build(DocumentReader.Start event)
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(org.w3c.dom.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 anInputNodethat 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(org.w3c.dom.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 anInputNodethat 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 useInputNodeobjects as they should only ever be able to extract their children.- Returns:
- this returns an end event to signify an element close
-
-