public class XMLUtils
extends java.lang.Object
Constructor and Description |
---|
XMLUtils() |
Modifier and Type | Method and Description |
---|---|
static org.w3c.dom.Document |
createDocument()
Creates W3C Document.
|
static org.w3c.dom.Document |
createDocument(java.lang.String xml)
Creates W3C Document from the xml.
|
static org.w3c.dom.Document |
createDocument(java.lang.String xml,
boolean allowExternalEntities)
Creates W3C Document from the xml.
|
static java.lang.String |
createXml(org.w3c.dom.Document document)
Creates XML from W3C Document from the xml.
|
static void |
disableExternalEntities(javax.xml.parsers.DocumentBuilderFactory factory)
Tries to set the features which disable inclusion of XML external
entities and DOCTYPE declarations.
|
static org.w3c.dom.Element |
findChild(org.w3c.dom.Element parent,
java.lang.String tagName)
Returns the child element with the specified tagName for the specified
parent element.
|
static java.util.List<org.w3c.dom.Element> |
findChildren(org.w3c.dom.Element parent,
java.lang.String tagName)
Returns the children elements with the specified tagName for the
specified parent element.
|
static java.lang.String |
getAttribute(org.w3c.dom.Node node,
java.lang.String name)
Extracts from node the attribute with the specified name.
|
static java.lang.String |
getCData(org.w3c.dom.Element element)
Extract the CDATA content of the specified element.
|
static org.w3c.dom.CDATASection |
getCDataNode(org.w3c.dom.Element element)
Returns element's CDATA child node (if it has one).
|
static org.w3c.dom.Node |
getChildByType(org.w3c.dom.Element element,
short nodeType)
Returns first of the element's child nodes that is of type
nodeType.
|
static java.lang.String |
getNamespaceUri(org.w3c.dom.Node node)
Gets the node namespace.
|
static java.lang.String |
getText(org.w3c.dom.Element parentNode)
Extracts the String content of a TXT element.
|
static org.w3c.dom.Text |
getTextNode(org.w3c.dom.Element element)
Returns element's TEXT child node (if it has one).
|
static boolean |
hasChildElements(org.w3c.dom.Element element)
Indicates whether element has any child element.
|
static void |
indentedWriteXML(org.w3c.dom.Document doc,
java.io.OutputStream out)
A simple implementation of XML writing that also allows for indentation.
|
static boolean |
isStandartXmlNamespace(java.lang.String namespace)
Indicates whether namespace is one of the standart xml namespace.
|
static org.w3c.dom.Element |
locateElement(org.w3c.dom.Element root,
java.lang.String tagName,
java.lang.String keyAttributeName,
java.lang.String keyAttributeValue)
Looks through all child elements of the specified root (recursively)
and returns the first element that corresponds to all parameters.
|
static java.util.List<org.w3c.dom.Element> |
locateElements(org.w3c.dom.Element root,
java.lang.String tagName,
java.lang.String keyAttributeName,
java.lang.String keyAttributeValue)
Looks through all child elements of the specified root (recursively) and
returns the elements that corresponds to all parameters.
|
static javax.xml.parsers.DocumentBuilderFactory |
newDocumentBuilderFactory()
Creates and returns a new DocumentBuilderFactory instance, and
sets the default set of features.
|
static javax.xml.parsers.DocumentBuilderFactory |
newDocumentBuilderFactory(boolean allowExternalEntities)
Creates and returns a new DocumentBuilderFactory instance, and
sets the default set of features.
|
static void |
printChildElements(org.w3c.dom.Element root,
java.io.PrintStream out,
boolean recurse,
java.lang.String prefix)
Whenever you'd need to print a configuration node and/or its children.
|
static void |
setCData(org.w3c.dom.Element element,
java.lang.String data)
Sets data to be the CDATA content of element
|
static void |
setText(org.w3c.dom.Element parentNode,
java.lang.String data)
Sets data to be the TEXT content of element
|
static void |
writeXML(org.w3c.dom.Document document,
java.io.File out)
Writes the specified document to the given file adding indentatation.
|
static void |
writeXML(org.w3c.dom.Document document,
javax.xml.transform.stream.StreamResult streamResult,
java.lang.String doctypeSystem,
java.lang.String doctypePublic)
Writes the specified document to the given file adding indentatation.
|
static void |
writeXML(org.w3c.dom.Document document,
java.io.Writer writer)
Writes the specified document to the given file adding indentatation.
|
public static java.lang.String getAttribute(org.w3c.dom.Node node, java.lang.String name)
node
- the node whose attribute we'd like to extract.name
- the name of the attribute to extract.public static java.lang.String getText(org.w3c.dom.Element parentNode)
parentNode
- the node containing the data that we'd like to get.public static void setText(org.w3c.dom.Element parentNode, java.lang.String data)
parentNode
- the parent element.data
- the data to set.public static void setCData(org.w3c.dom.Element element, java.lang.String data)
element
- the parent element.data
- the data to set.public static java.lang.String getCData(org.w3c.dom.Element element)
element
- the element whose data we needpublic static org.w3c.dom.CDATASection getCDataNode(org.w3c.dom.Element element)
element
- the element whose CDATA we need to get.public static org.w3c.dom.Text getTextNode(org.w3c.dom.Element element)
element
- the element whose TEXT we need to get.public static org.w3c.dom.Node getChildByType(org.w3c.dom.Element element, short nodeType)
element
- the element whose child we need.nodeType
- the type of the child we need.public static void writeXML(org.w3c.dom.Document document, java.io.File out) throws java.io.IOException
out
- the output Filedocument
- the document to writejava.io.IOException
- in case a TransformerException is thrown by
the underlying Transformer.public static void writeXML(org.w3c.dom.Document document, java.io.Writer writer) throws java.io.IOException
writer
- the writer to use when writing the Filedocument
- the document to writejava.io.IOException
- in case a TransformerException is thrown by
the underlying Transformer.public static void writeXML(org.w3c.dom.Document document, javax.xml.transform.stream.StreamResult streamResult, java.lang.String doctypeSystem, java.lang.String doctypePublic) throws java.io.IOException
streamResult
- the streamResult object where the document should be
writtendocument
- the document to writedoctypeSystem
- the doctype system of the xml document that we should
record in the file or null if none is specified.doctypePublic
- the public identifier to be used in the document
type declaration.java.io.IOException
- in case a TransformerException is thrown by
the underlying Transformer.public static void indentedWriteXML(org.w3c.dom.Document doc, java.io.OutputStream out)
doc
- the Document that we will be writing.out
- an OutputStream to write the document through.public static void printChildElements(org.w3c.dom.Element root, java.io.PrintStream out, boolean recurse, java.lang.String prefix)
root
- the root node to print.out
- the print stream that should be used to outpurecurse
- booleanprefix
- Stringpublic static org.w3c.dom.Element findChild(org.w3c.dom.Element parent, java.lang.String tagName)
parent
- The parent whose child we're looking for.tagName
- the name of the child to findjava.lang.NullPointerException
- if parent or tagName are nullpublic static java.util.List<org.w3c.dom.Element> findChildren(org.w3c.dom.Element parent, java.lang.String tagName)
parent
- The parent whose children we're looking for.tagName
- the name of the child to findjava.lang.NullPointerException
- if parent or tagName are nullpublic static org.w3c.dom.Element locateElement(org.w3c.dom.Element root, java.lang.String tagName, java.lang.String keyAttributeName, java.lang.String keyAttributeValue)
root
- the Element where the search should begintagName
- the name of the node we're looking forkeyAttributeName
- the name of an attribute that the node has to
havekeyAttributeValue
- the value that attribute must havejava.lang.NullPointerException
- if any of the arguments is null.public static java.util.List<org.w3c.dom.Element> locateElements(org.w3c.dom.Element root, java.lang.String tagName, java.lang.String keyAttributeName, java.lang.String keyAttributeValue)
root
- the Element where the search should begintagName
- the name of the node we're looking forkeyAttributeName
- the name of an attribute that the node has to
havekeyAttributeValue
- the value that attribute must havejava.lang.NullPointerException
- if any of the arguments is null.public static boolean isStandartXmlNamespace(java.lang.String namespace)
namespace
- the namespace to analyze.public static java.lang.String getNamespaceUri(org.w3c.dom.Node node)
node
- the Element or Attr node to analyze.public static boolean hasChildElements(org.w3c.dom.Element element)
element
- the namespace to analyze.public static org.w3c.dom.Document createDocument() throws java.lang.Exception
java.lang.Exception
- is there is some error during operation.public static org.w3c.dom.Document createDocument(java.lang.String xml, boolean allowExternalEntities) throws java.lang.Exception
xml
- the xml that needs to be converted.allowExternalEntities
- whether parsing of XML external entities
and DOCTYPE declarations should be allowed.java.lang.Exception
- is there is some error during operation.public static org.w3c.dom.Document createDocument(java.lang.String xml) throws java.lang.Exception
xml
- the xml that needs to be converted.java.lang.Exception
- is there is some error during operation.public static java.lang.String createXml(org.w3c.dom.Document document) throws java.lang.Exception
document
- the xml that needs to be converted.java.lang.Exception
- is there is some error during operation.public static javax.xml.parsers.DocumentBuilderFactory newDocumentBuilderFactory() throws javax.xml.parsers.ParserConfigurationException
javax.xml.parsers.ParserConfigurationException
- if setting a feature fails.public static javax.xml.parsers.DocumentBuilderFactory newDocumentBuilderFactory(boolean allowExternalEntities) throws javax.xml.parsers.ParserConfigurationException
allowExternalEntities
- whether parsing of XML external entities
and DOCTYPE declarations should be allowed.javax.xml.parsers.ParserConfigurationException
- if setting a feature fails.public static void disableExternalEntities(javax.xml.parsers.DocumentBuilderFactory factory) throws javax.xml.parsers.ParserConfigurationException
factory
- the factoryjavax.xml.parsers.ParserConfigurationException
- if setting any
of the features fails.
Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under Apache license.