public class XmlParser
extends java.lang.Object
Parser for XML.
Supports parsing into an XmlDocument
or XmlElement
.
Parsing options are complete (XmlParser.parseDocument
, XmlParser.parseElement
) and streamed (XmlParser.startDocument
, XmlParser.startElement
).
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getDeclaration()
(nullable) The parsed XML declaration.
|
XmlElement |
getRootElement()
The parsed root element.
|
XmlNode |
nextChild(XmlElement element,
boolean parseNested)
Return (nullable) The next child node of
element , or null if element has ended. |
XmlElement |
nextChildElement(XmlElement element,
boolean parseNested)
Return (nullable) The next child element of
element , or null if element has ended. |
XmlElement |
nextElement()
Assuming an element appears next in the stream, parse its start tag.
|
static XmlDocument |
parseDocument(CharStream stream,
boolean mixed)
Parse a stream to a document.
|
XmlElement |
parseElement()
Return the next element in the stream.
|
void |
readChildren(XmlElement element)
Read all of the children of a started element, and read the element's end tag.
|
void |
setDeclaration(java.lang.String value)
The parsed XML declaration.
|
void |
setRootElement(XmlElement value)
The parsed root element.
|
static XmlParser |
startDocument(CharStream stream,
boolean mixed)
Start parsing a stream to a document.
|
static XmlParser |
startElement(CharStream stream,
boolean mixed)
Start parsing a stream to an element.
|
static XmlElement |
static_parseElement(CharStream stream,
boolean mixed)
Parse a stream to an element.
|
public java.lang.String getDeclaration()
(nullable) The parsed XML declaration.
public XmlElement getRootElement()
The parsed root element.
public XmlNode nextChild(XmlElement element, boolean parseNested)
Return (nullable) The next child node of element
, or null
if element
has ended.
element
- Parent element, which must have already been started.parseNested
- true
if child elements should be XmlParser.parseElement
, false
if they should be XmlParser.startElement
.element
, or null
if element
has ended.public XmlElement nextChildElement(XmlElement element, boolean parseNested)
Return (nullable) The next child element of element
, or null
if element
has ended.
Any non-element child nodes (e.g. comment nodes, text nodes) will be ignored.
element
- Parent element, which must have already been started.parseNested
- true
if child elements should be XmlParser.parseElement
, false
if they should be XmlParser.startElement
.element
, or null
if element
has ended.public XmlElement nextElement()
Assuming an element appears next in the stream, parse its start tag.
public static XmlDocument parseDocument(CharStream stream, boolean mixed)
Parse a stream to a document.
stream
- Stream to be parsed.mixed
- true
if mixed content is permitted, otherwise false
. Parsing may be faster with mixed
= false
, since text nodes can be omitted from elements which have non-text content.public XmlElement parseElement()
Return the next element in the stream.
public void readChildren(XmlElement element)
Read all of the children of a started element, and read the element's end tag.
element
- Parent element, which must have already been started.public void setDeclaration(java.lang.String value)
The parsed XML declaration.
public void setRootElement(XmlElement value)
The parsed root element.
public static XmlParser startDocument(CharStream stream, boolean mixed)
Start parsing a stream to a document.
stream
- Stream to be parsed.mixed
- true
if mixed content is permitted, otherwise false
. Parsing may be faster with mixed
= false
, since text nodes can be omitted from elements which have non-text content.public static XmlParser startElement(CharStream stream, boolean mixed)
Start parsing a stream to an element.
stream
- Stream to be parsed.mixed
- true
if mixed content is permitted, otherwise false
. Parsing may be faster with mixed
= false
, since text nodes can be omitted from elements which have non-text content.public static XmlElement static_parseElement(CharStream stream, boolean mixed)
Parse a stream to an element.
stream
- Stream to be parsed.mixed
- true
if mixed content is permitted, otherwise false
. Parsing may be faster with mixed
= false
, since text nodes can be omitted from elements which have non-text content.