public class PositionXmlParser
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static org.w3c.dom.Node |
findNodeAtLineAndCol(org.w3c.dom.Document document,
int line,
int column)
Finds the leaf node at the given offset
|
static org.w3c.dom.Node |
findNodeAtOffset(org.w3c.dom.Document document,
int offset)
Finds the leaf node at the given offset
|
static SourcePosition |
getPosition(org.w3c.dom.Node node)
Returns the position for the given node.
|
static SourcePosition |
getPosition(org.w3c.dom.Node node,
int start,
int end)
Returns the position for the given node.
|
static java.lang.String |
getXmlString(byte[] data)
Returns the String corresponding to the given byte array of XML data
(with unknown encoding).
|
static java.lang.String |
getXmlString(byte[] data,
java.lang.String defaultCharset)
Returns the String corresponding to the given byte array of XML data
(with unknown encoding).
|
static org.w3c.dom.Document |
parse(byte[] data) |
static org.w3c.dom.Document |
parse(byte[] data,
boolean checkDtd)
Parses the XML content from the given byte array
|
static org.w3c.dom.Document |
parse(java.io.InputStream input) |
static org.w3c.dom.Document |
parse(java.io.InputStream input,
boolean checkDtd)
Parses the XML content from the given input stream.
|
static org.w3c.dom.Document |
parse(java.lang.String xml)
Parses the given XML content.
|
@NonNull public static org.w3c.dom.Document parse(@NonNull java.io.InputStream input, boolean checkDtd) throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException, java.io.IOException
input
- the input stream containing the XML to be parsedcheckDtd
- whether or not download the DTD and validate itjavax.xml.parsers.ParserConfigurationException
- if a SAX parser is not availableorg.xml.sax.SAXException
- if the document contains a parsing errorjava.io.IOException
- if something is seriously wrong. This should not
happen since the input source is known to be constructed from
a string.@NonNull public static org.w3c.dom.Document parse(@NonNull java.io.InputStream input) throws java.io.IOException, org.xml.sax.SAXException, javax.xml.parsers.ParserConfigurationException
java.io.IOException
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
parse(InputStream, boolean)
@NonNull public static org.w3c.dom.Document parse(@NonNull byte[] data) throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException, java.io.IOException
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
java.io.IOException
parse(byte[], boolean)
@NonNull public static org.w3c.dom.Document parse(@NonNull byte[] data, boolean checkDtd) throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException, java.io.IOException
data
- the raw XML data (with unknown encoding)checkDtd
- whether or not download the DTD and validate itjavax.xml.parsers.ParserConfigurationException
- if a SAX parser is not availableorg.xml.sax.SAXException
- if the document contains a parsing errorjava.io.IOException
- if something is seriously wrong. This should not
happen since the input source is known to be constructed from
a string.@NonNull public static org.w3c.dom.Document parse(@NonNull java.lang.String xml) throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException, java.io.IOException
xml
- the XML string to be parsed. This must be in the correct
encoding already.javax.xml.parsers.ParserConfigurationException
- if a SAX parser is not availableorg.xml.sax.SAXException
- if the document contains a parsing errorjava.io.IOException
- if something is seriously wrong. This should not
happen since the input source is known to be constructed from
a string.@NonNull public static java.lang.String getXmlString(@NonNull byte[] data)
data
- the XML data to be decoded into a string@NonNull public static java.lang.String getXmlString(@NonNull byte[] data, @NonNull java.lang.String defaultCharset)
data
- the XML data to be decoded into a stringdefaultCharset
- the default charset to use if not specified by an encoding prologue
attribute or a byte order mark@NonNull public static SourcePosition getPosition(@NonNull org.w3c.dom.Node node)
Position#getEnd()
.node
- the node to look up position for@NonNull public static SourcePosition getPosition(@NonNull org.w3c.dom.Node node, int start, int end)
Position#getEnd()
. A specific
range within the node can be specified with the start
and
end
parameters.node
- the node to look up position forstart
- the relative offset within the node range to use as the
starting position, inclusive, or -1 to not limit the rangeend
- the relative offset within the node range to use as the ending
position, or -1 to not limit the range@Nullable public static org.w3c.dom.Node findNodeAtOffset(@NonNull org.w3c.dom.Document document, int offset)
document
- root nodeoffset
- offset to look for@Nullable public static org.w3c.dom.Node findNodeAtLineAndCol(@NonNull org.w3c.dom.Document document, int line, int column)
document
- root nodeline
- the linecolumn
- the column, or -1