public class XmlUtils extends Object
| Constructor and Description |
|---|
XmlUtils() |
| Modifier and Type | Method and Description |
|---|---|
static void |
clean(Node node)
Recursively remove any comments and unnecessary white spaces from a
Node and its children. |
static int |
countNodes(String xpathExpression,
Document doc)
Count the number of nodes, that are matching against an XPath expression.
|
static int |
countNodes(String xpathExpression,
Document doc,
Object context)
Count the number of nodes, that are matching against an XPath expression.
|
static Element |
getRootElement(Document doc)
|
static Document |
newDocument()
Create an empty
Document. |
static Document |
newDocument(boolean namespaceAware)
Create an empty
Document. |
static Document |
newDocument(File xmlFile)
|
static Document |
newDocument(File xmlFile,
boolean namespaceAware)
|
static Document |
newDocument(InputSource xmlSource)
Create a
Document from an InputSource. |
static Document |
newDocument(InputSource xmlSource,
boolean namespaceAware)
Create a
Document from an InputSource. |
static Document |
newDocument(InputStream xmlStream)
Create a
Document from an InputStream. |
static Document |
newDocument(InputStream xmlStream,
boolean namespaceAware)
Create a
Document from an InputStream. |
static Document |
newDocument(String xmlString)
Create a
Document from a XML string. |
static Document |
newDocument(String xmlString,
boolean namespaceAware)
Create a
Document from a XML string. |
static org.jaxen.XPath |
newXPath(String expression)
Create a
XPath expression. |
static org.jaxen.XPath |
newXPath(String expression,
Document doc)
Create a
XPath expression. |
static org.jaxen.XPath |
newXPath(String expression,
Document doc,
String namespacePrefix)
Create a
XPath expression. |
static void |
printNode(Element node)
Print an
Element and its children to the local logger. |
static void |
printNodes(Document doc)
Print nodes of a
Document recursively to the local logger. |
static void |
replaceNamespace(Document doc,
Node node,
String newNamespaceURI)
Replace the namespace of a
Node and its children. |
static void |
replaceNamespace(Document doc,
String newNamespaceURI)
|
static void |
replaceTextWithCData(Document doc)
Replace all text values of a
Document with CDATA values. |
static void |
replaceTextWithCData(Document doc,
Node node)
Replace all text values of a
Node with CDATA values. |
static void |
write(Document doc,
File file)
|
static void |
write(Document doc,
File file,
boolean prettyPrint)
|
static void |
write(Document doc,
OutputStream output)
Write a
Document to an OutputStream. |
static void |
write(Document doc,
OutputStream output,
boolean prettyPrint)
Write a
Document to an OutputStream. |
static void |
write(Document doc,
Writer output)
|
static void |
write(Document doc,
Writer output,
boolean prettyPrint)
|
public static void clean(Node node)
Node and its children.node - the node to cleanpublic static int countNodes(String xpathExpression, Document doc) throws org.jaxen.JaxenException
xpathExpression - the XPath expression to matchdoc - the document, on which the XPath expression is evaluatedorg.jaxen.JaxenException - if the XPath evaluation failedpublic static int countNodes(String xpathExpression, Document doc, Object context) throws org.jaxen.JaxenException
xpathExpression - the XPath expression to matchcontext - the node, on which the XPath expression is evaluatedorg.jaxen.JaxenException - if the XPath evaluation failedpublic static Element getRootElement(Document doc)
doc - the document, where the root element is looked uppublic static Document newDocument() throws ParserConfigurationException
Document.ParserConfigurationException - if the parser is not properly configuredpublic static Document newDocument(boolean namespaceAware) throws ParserConfigurationException
Document.namespaceAware - if namespaces are used in the created documentParserConfigurationException - if the parser is not properly configuredpublic static Document newDocument(String xmlString) throws SAXException, IOException, ParserConfigurationException
Document from a XML string.xmlString - the XML string, the document is created fromSAXException - if XML contains an errorIOException - if XML is not readableParserConfigurationException - if the parser is not properly configuredpublic static Document newDocument(String xmlString, boolean namespaceAware) throws SAXException, IOException, ParserConfigurationException
Document from a XML string.xmlString - the XML string, the document is created fromnamespaceAware - if namespaces are used in the created documentSAXException - if XML contains an errorIOException - if XML is not readableParserConfigurationException - if the parser is not properly configuredpublic static Document newDocument(InputSource xmlSource) throws SAXException, IOException, ParserConfigurationException
Document from an InputSource.xmlSource - the XML input, the document is created fromSAXException - if XML contains an errorIOException - if XML is not readableParserConfigurationException - if the parser is not properly configuredpublic static Document newDocument(InputSource xmlSource, boolean namespaceAware) throws SAXException, IOException, ParserConfigurationException
Document from an InputSource.xmlSource - the XML input, the document is created fromnamespaceAware - if namespaces are used in the created documentSAXException - if XML contains an errorIOException - if XML is not readableParserConfigurationException - if the parser is not properly configuredpublic static Document newDocument(InputStream xmlStream) throws SAXException, IOException, ParserConfigurationException
Document from an InputStream.xmlStream - the XML input, the document is created fromSAXException - if XML contains an errorIOException - if XML is not readableParserConfigurationException - if the parser is not properly configuredpublic static Document newDocument(InputStream xmlStream, boolean namespaceAware) throws SAXException, IOException, ParserConfigurationException
Document from an InputStream.xmlStream - the XML input, the document is created fromnamespaceAware - if namespaces are used in the created documentSAXException - if XML contains an errorIOException - if XML is not readableParserConfigurationException - if the parser is not properly configuredpublic static Document newDocument(File xmlFile) throws SAXException, IOException, ParserConfigurationException
xmlFile - the XML file, the document is created fromSAXException - if XML contains an errorIOException - if XML is not readableParserConfigurationException - if the parser is not properly configuredpublic static Document newDocument(File xmlFile, boolean namespaceAware) throws SAXException, IOException, ParserConfigurationException
xmlFile - the XML file, the document is created fromnamespaceAware - if namespaces are used in the created documentSAXException - if XML contains an errorIOException - if XML is not readableParserConfigurationException - if the parser is not properly configuredpublic static org.jaxen.XPath newXPath(String expression) throws org.jaxen.JaxenException
XPath expression.expression - string with the XPath expression to createorg.jaxen.JaxenException - if the XPath is not creatablepublic static org.jaxen.XPath newXPath(String expression, Document doc) throws org.jaxen.JaxenException
XPath expression.expression - string with the XPath expression to createdoc - the document, whose namespace is bound to the XPath expressionorg.jaxen.JaxenException - if the XPath is not creatablepublic static org.jaxen.XPath newXPath(String expression, Document doc, String namespacePrefix) throws org.jaxen.JaxenException
XPath expression.expression - string with the XPath expression to createdoc - the document, whose namespace is bound to the XPath expressionnamespacePrefix - prefix of the document namespace, that is bound to the XPath expressionorg.jaxen.JaxenException - if the XPath is not creatablepublic static void printNodes(Document doc)
Document recursively to the local logger.doc - the document to printpublic static void printNode(Element node)
Element and its children to the local logger.node - the element to printpublic static void replaceNamespace(Document doc, String newNamespaceURI)
doc - the document to updatenewNamespaceURI - the new namespace URIpublic static void replaceNamespace(Document doc, Node node, String newNamespaceURI)
Node and its children.doc - the document to updatenode - the node to updatenewNamespaceURI - the new namespace URIpublic static void replaceTextWithCData(Document doc)
Document with CDATA values.doc - the document to updatepublic static void replaceTextWithCData(Document doc, Node node)
Node with CDATA values.doc - the document to updatenode - the node to updatepublic static void write(Document doc, File file) throws TransformerException, IOException
doc - the document to writefile - the file, where the document is written toTransformerException - if XML transformation failedIOException - if writing failedpublic static void write(Document doc, File file, boolean prettyPrint) throws TransformerException, IOException
doc - the document to writefile - the file, where the document is written toprettyPrint - if pretty printing is enabled for the generated XML codeTransformerException - if XML transformation failedIOException - if writing failedpublic static void write(Document doc, OutputStream output) throws TransformerException
Document to an OutputStream.doc - the document to writeoutput - the output, where the document is written toTransformerException - if XML transformation failedpublic static void write(Document doc, OutputStream output, boolean prettyPrint) throws TransformerException
Document to an OutputStream.doc - the document to writeoutput - the output, where the document is written toprettyPrint - if pretty printing is enabled for the generated XML codeTransformerException - if XML transformation failedpublic static void write(Document doc, Writer output) throws TransformerException
doc - the document to writeoutput - the output, where the document is written toTransformerException - if XML transformation failedpublic static void write(Document doc, Writer output, boolean prettyPrint) throws TransformerException
doc - the document to writeoutput - the output, where the document is written toprettyPrint - if pretty printing is enabled for the generated XML codeTransformerException - if XML transformation failedCopyright © 2015 OpenEstate. All rights reserved.