Modifier and Type | Method and Description |
---|---|
static void |
applyXXEProtection(DocumentBuilderFactory factory)
Configures a
DocumentBuilderFactory to protect it against XML
External Entity attacks. |
static void |
applyXXEProtection(TransformerFactory factory)
Configures a
TransformerFactory to protect it against XML
External Entity attacks. |
static void |
assignOutputProperties(Transformer transformer,
Map<String,String> outputProperties)
Assigns the given output properties to the given transformer, ignoring
invalid output properties.
|
static Document |
createDocument()
Creates a new XML document.
|
static Element |
getFirstChildElement(Element parent)
Gets the first child element of an element.
|
static boolean |
hasQName(Node node,
QName qname)
Determines if a node has a particular qualified name.
|
static Document |
toDocument(File file)
Parses an XML document from a file.
|
static Document |
toDocument(InputStream in)
Parses an XML document from an input stream.
|
static Document |
toDocument(Reader reader)
Parses an XML document from a reader.
|
static Document |
toDocument(String xml)
Parses an XML string into a DOM.
|
static List<Element> |
toElementList(NodeList nodeList)
Gets all the elements out of a
NodeList . |
static String |
toString(Node node)
Converts an XML node to a string.
|
static String |
toString(Node node,
Map<String,String> outputProperties)
Converts an XML node to a string.
|
static void |
toWriter(Node node,
Writer writer)
Writes an XML node to a writer.
|
static void |
toWriter(Node node,
Writer writer,
Map<String,String> outputProperties)
Writes an XML node to a writer.
|
public static Document createDocument()
public static Document toDocument(String xml) throws SAXException
xml
- the XML stringSAXException
- if the string is not valid XMLpublic static Document toDocument(File file) throws SAXException, IOException
file
- the fileSAXException
- if the XML is not validIOException
- if there is a problem reading from the filepublic static Document toDocument(InputStream in) throws SAXException, IOException
in
- the input streamSAXException
- if the XML is not validIOException
- if there is a problem reading from the input streampublic static Document toDocument(Reader reader) throws SAXException, IOException
Parses an XML document from a reader.
Note that use of this method is discouraged. It ignores the character
encoding that is defined within the XML document itself, and should only
be used if the encoding is undefined or if the encoding needs to be
ignored for whatever reason. The toDocument(InputStream)
method
should be used instead, since it takes the XML document's character
encoding into account when parsing.
reader
- the readerSAXException
- if the XML is not validIOException
- if there is a problem reading from the readerpublic static void applyXXEProtection(DocumentBuilderFactory factory)
DocumentBuilderFactory
to protect it against XML
External Entity attacks.factory
- the factorypublic static void applyXXEProtection(TransformerFactory factory)
TransformerFactory
to protect it against XML
External Entity attacks.factory
- the factorypublic static String toString(Node node)
node
- the XML nodepublic static String toString(Node node, Map<String,String> outputProperties)
node
- the XML nodeoutputProperties
- the output propertiespublic static void toWriter(Node node, Writer writer) throws TransformerException
node
- the XML nodewriter
- the writerTransformerException
- if there's a problem writing to the writerpublic static void toWriter(Node node, Writer writer, Map<String,String> outputProperties) throws TransformerException
node
- the XML nodewriter
- the writeroutputProperties
- the output propertiesTransformerException
- if there's a problem writing to the writerpublic static void assignOutputProperties(Transformer transformer, Map<String,String> outputProperties)
transformer
- the transformeroutputProperties
- the output propertiespublic static List<Element> toElementList(NodeList nodeList)
NodeList
.nodeList
- the node listpublic static Element getFirstChildElement(Element parent)
parent
- the parent elementCopyright © 2012–2020 Michael Angstadt. All rights reserved.