public class XMLUtils extends Object
| Constructor and Description |
|---|
XMLUtils() |
| Modifier and Type | Method and Description |
|---|---|
static Document |
createDocument()
Creates W3C Document.
|
static Document |
createDocument(String xml)
Creates W3C Document from the xml.
|
static Document |
createDocument(String xml,
boolean allowExternalEntities)
Creates W3C Document from the xml.
|
static String |
createXml(Document document)
Creates XML from W3C Document from the xml.
|
static void |
disableExternalEntities(DocumentBuilderFactory factory)
Tries to set the features which disable inclusion of XML external
entities and DOCTYPE declarations.
|
static Element |
findChild(Element parent,
String tagName)
Returns the child element with the specified tagName for the specified
parent element.
|
static List<Element> |
findChildren(Element parent,
String tagName)
Returns the children elements with the specified tagName for the
specified parent element.
|
static String |
getAttribute(Node node,
String name)
Extracts from node the attribute with the specified name.
|
static String |
getCData(Element element)
Extract the CDATA content of the specified element.
|
static CDATASection |
getCDataNode(Element element)
Returns element's CDATA child node (if it has one).
|
static Node |
getChildByType(Element element,
short nodeType)
Returns first of the element's child nodes that is of type
nodeType.
|
static String |
getNamespaceUri(Node node)
Gets the node namespace.
|
static String |
getText(Element parentNode)
Extracts the String content of a TXT element.
|
static Text |
getTextNode(Element element)
Returns element's TEXT child node (if it has one).
|
static boolean |
hasChildElements(Element element)
Indicates whether element has any child element.
|
static void |
indentedWriteXML(Document doc,
OutputStream out)
A simple implementation of XML writing that also allows for indentation.
|
static boolean |
isStandartXmlNamespace(String namespace)
Indicates whether namespace is one of the standart xml namespace.
|
static Element |
locateElement(Element root,
String tagName,
String keyAttributeName,
String keyAttributeValue)
Looks through all child elements of the specified root (recursively)
and returns the first element that corresponds to all parameters.
|
static List<Element> |
locateElements(Element root,
String tagName,
String keyAttributeName,
String keyAttributeValue)
Looks through all child elements of the specified root (recursively) and
returns the elements that corresponds to all parameters.
|
static DocumentBuilderFactory |
newDocumentBuilderFactory()
Creates and returns a new DocumentBuilderFactory instance, and
sets the default set of features.
|
static DocumentBuilderFactory |
newDocumentBuilderFactory(boolean allowExternalEntities)
Creates and returns a new DocumentBuilderFactory instance, and
sets the default set of features.
|
static void |
printChildElements(Element root,
PrintStream out,
boolean recurse,
String prefix)
Whenever you'd need to print a configuration node and/or its children.
|
static void |
setCData(Element element,
String data)
Sets data to be the CDATA content of element
|
static void |
setText(Element parentNode,
String data)
Sets data to be the TEXT content of element
|
static void |
writeXML(Document document,
File out)
Writes the specified document to the given file adding indentatation.
|
static void |
writeXML(Document document,
StreamResult streamResult,
String doctypeSystem,
String doctypePublic)
Writes the specified document to the given file adding indentatation.
|
static void |
writeXML(Document document,
Writer writer)
Writes the specified document to the given file adding indentatation.
|
public static String getAttribute(Node node, String name)
node - the node whose attribute we'd like to extract.name - the name of the attribute to extract.public static String getText(Element parentNode)
parentNode - the node containing the data that we'd like to get.public static void setText(Element parentNode, String data)
parentNode - the parent element.data - the data to set.public static void setCData(Element element, String data)
element - the parent element.data - the data to set.public static String getCData(Element element)
element - the element whose data we needpublic static CDATASection getCDataNode(Element element)
element - the element whose CDATA we need to get.public static Text getTextNode(Element element)
element - the element whose TEXT we need to get.public static Node getChildByType(Element element, short nodeType)
element - the element whose child we need.nodeType - the type of the child we need.public static void writeXML(Document document, File out) throws IOException
out - the output Filedocument - the document to writeIOException - in case a TransformerException is thrown by
the underlying Transformer.public static void writeXML(Document document, Writer writer) throws IOException
writer - the writer to use when writing the Filedocument - the document to writeIOException - in case a TransformerException is thrown by
the underlying Transformer.public static void writeXML(Document document, StreamResult streamResult, String doctypeSystem, String doctypePublic) throws 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.IOException - in case a TransformerException is thrown by
the underlying Transformer.public static void indentedWriteXML(Document doc, OutputStream out)
doc - the Document that we will be writing.out - an OutputStream to write the document through.public static void printChildElements(Element root, PrintStream out, boolean recurse, String prefix)
root - the root node to print.out - the print stream that should be used to outpurecurse - booleanprefix - Stringpublic static Element findChild(Element parent, String tagName)
parent - The parent whose child we're looking for.tagName - the name of the child to findNullPointerException - if parent or tagName are nullpublic static List<Element> findChildren(Element parent, String tagName)
parent - The parent whose children we're looking for.tagName - the name of the child to findNullPointerException - if parent or tagName are nullpublic static Element locateElement(Element root, String tagName, String keyAttributeName, 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 haveNullPointerException - if any of the arguments is null.public static List<Element> locateElements(Element root, String tagName, String keyAttributeName, 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 haveNullPointerException - if any of the arguments is null.public static boolean isStandartXmlNamespace(String namespace)
namespace - the namespace to analyze.public static String getNamespaceUri(Node node)
node - the Element or Attr node to analyze.public static boolean hasChildElements(Element element)
element - the namespace to analyze.public static Document createDocument() throws Exception
Exception - is there is some error during operation.public static Document createDocument(String xml, boolean allowExternalEntities) throws Exception
xml - the xml that needs to be converted.allowExternalEntities - whether parsing of XML external entities
and DOCTYPE declarations should be allowed.Exception - is there is some error during operation.public static Document createDocument(String xml) throws Exception
xml - the xml that needs to be converted.Exception - is there is some error during operation.public static String createXml(Document document) throws Exception
document - the xml that needs to be converted.Exception - is there is some error during operation.public static DocumentBuilderFactory newDocumentBuilderFactory() throws ParserConfigurationException
ParserConfigurationException - if setting a feature fails.public static DocumentBuilderFactory newDocumentBuilderFactory(boolean allowExternalEntities) throws ParserConfigurationException
allowExternalEntities - whether parsing of XML external entities
and DOCTYPE declarations should be allowed.ParserConfigurationException - if setting a feature fails.public static void disableExternalEntities(DocumentBuilderFactory factory) throws ParserConfigurationException
factory - the factoryParserConfigurationException - if setting any
of the features fails.Copyright © 2021 jitsi.org. All rights reserved.