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 | Class and Description |
---|---|
static class |
XmlParser.Options
XMP parser options
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getDeclaration()
Return (nullable) The parsed XML declaration.
|
XmlElement |
getRootElement()
Return 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)
|
static XmlDocument |
parseDocument(CharStream stream,
boolean mixed)
|
static XmlDocument |
parseDocument(CharStream stream,
boolean mixed,
XmlParser.Options options)
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)
Set the parsed XML declaration.
|
void |
setRootElement(XmlElement value)
Set the parsed root element.
|
static XmlParser |
startDocument(CharStream stream)
|
static XmlParser |
startDocument(CharStream stream,
boolean mixed)
|
static XmlParser |
startDocument(CharStream stream,
boolean mixed,
XmlParser.Options options)
Start parsing a stream to a document.
|
static XmlParser |
startElement(CharStream stream)
|
static XmlParser |
startElement(CharStream stream,
boolean mixed)
|
static XmlParser |
startElement(CharStream stream,
boolean mixed,
XmlParser.Options options)
Start parsing a stream to an element.
|
static XmlElement |
static_parseElement(CharStream stream)
|
static XmlElement |
static_parseElement(CharStream stream,
boolean mixed)
|
static XmlElement |
static_parseElement(CharStream stream,
boolean mixed,
XmlParser.Options options)
Parse a stream to an element.
|
public java.lang.String getDeclaration()
Return (nullable) The parsed XML declaration.
public XmlElement getRootElement()
Return 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)
stream
- Stream parameter.public static XmlDocument parseDocument(CharStream stream, boolean mixed)
stream
- Stream parameter.mixed
- Mixed parameter.public static XmlDocument parseDocument(CharStream stream, boolean mixed, XmlParser.Options options)
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.options
- Additional parser options (if any).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)
Set the parsed XML declaration.
value
- The parsed XML declaration.public void setRootElement(XmlElement value)
Set the parsed root element.
value
- The parsed root element.public static XmlParser startDocument(CharStream stream)
stream
- Stream parameter.public static XmlParser startDocument(CharStream stream, boolean mixed)
stream
- Stream parameter.mixed
- Mixed parameter.public static XmlParser startDocument(CharStream stream, boolean mixed, XmlParser.Options options)
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.options
- Additional parser options (if any).public static XmlParser startElement(CharStream stream)
stream
- Stream parameter.public static XmlParser startElement(CharStream stream, boolean mixed)
stream
- Stream parameter.mixed
- Mixed parameter.public static XmlParser startElement(CharStream stream, boolean mixed, XmlParser.Options options)
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.options
- Additional parser options (if any).public static XmlElement static_parseElement(CharStream stream)
stream
- Stream parameter.public static XmlElement static_parseElement(CharStream stream, boolean mixed)
stream
- Stream parameter.mixed
- Mixed parameter.public static XmlElement static_parseElement(CharStream stream, boolean mixed, XmlParser.Options options)
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.options
- Additional parser options (if any).