public class XMLTools extends Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
XMLTools.Filter<N extends Node> |
| Modifier and Type | Field and Description |
|---|---|
static String |
ATTRIB_CDATA_SECTION_ELEMENTS
.
|
static String |
ATTRIB_HREF
.
|
static String |
ATTRIB_INDENT
.
|
static String |
ATTRIB_METHOD
.
|
static String |
ATTRIB_OMIT_XML_DECLARATION
.
|
static boolean |
DEFAULT_NAMESPACE_AWARE
.
|
static boolean |
DEFAULT_VALIDATION
.
|
static String |
DIRECTIVE_IMPORT
.
|
static String |
DIRECTIVE_INCLUDE
.
|
static String |
PARAM_NO
.
|
static String |
PARAM_YES
.
|
static String |
XML_LANG_NAMESPACE_URI
Namespace URI for XML lang.
|
| Modifier and Type | Method and Description |
|---|---|
static String |
asString(Element element)
Perform trimming by default
|
static String |
asString(Element element,
boolean trim)
Get the element's content as a string.
|
static XMLTools.Filter<Element> |
byName(String uri,
Set<String> names) |
static XMLTools.Filter<Element> |
byName(String uri,
String name) |
static List<Element> |
getChildren(Element element)
Return all the children of the given element.
|
static List<Element> |
getChildren(Element element,
String name)
Return all the children of the given element having the specified name.
|
static List<Element> |
getChildren(Element element,
String uri,
String name)
Return all the children of the given element having the optionally specified name and the namespace URI.
|
static <T extends Node> |
getChildren(Node node,
XMLTools.Filter<T> filter)
Return all the children of the given node that match the provided filter.
|
static Iterator<Element> |
getChildrenIterator(Element element)
Return an iterator for all the children of the given element.
|
static Iterator<Element> |
getChildrenIterator(Element element,
String name)
Return an iterator for all the children of the given element having the specified name.
|
static Iterator<Element> |
getChildrenIterator(Element element,
String uri,
String name)
Return an iterator for all the children of the given element having the specified name and the optionally
specified namesspace uri.
|
static DocumentBuilderFactory |
getDocumentBuilderFactory()
Return the builder factory.
|
static Element |
getUniqueChild(Element element,
boolean strict)
Return the optional unique child of an element.
|
static Element |
getUniqueChild(Element element,
String name,
boolean strict)
Return an optional child of an element with the specified name.
|
static Element |
getUniqueChild(Element element,
String uri,
String name,
boolean strict)
Return an optional child of an element with the specified name and the optionally specified namespace uri.
|
static Properties |
loadXMLProperties(Document doc) |
static Properties |
loadXMLProperties(Element propertiesElt) |
static Document |
toDocument(Element element) |
static Document |
toDocument(String text)
Parse a string into a document.
|
static Element |
toElement(String text)
Parse a string into an element.
|
static String |
toString(Document doc)
Serialize the document with the default format : - No XML declaration - Indented - Encoding is UTF-8
|
static String |
toString(Document doc,
boolean omitXMLDeclaration,
boolean standalone,
boolean indented,
String encoding) |
static String |
toString(Element element) |
public static final String XML_LANG_NAMESPACE_URI
public static final String PARAM_YES
public static final String PARAM_NO
public static final String ATTRIB_OMIT_XML_DECLARATION
public static final String ATTRIB_CDATA_SECTION_ELEMENTS
public static final String ATTRIB_METHOD
public static final String ATTRIB_INDENT
public static final String ATTRIB_HREF
public static final String DIRECTIVE_IMPORT
public static final String DIRECTIVE_INCLUDE
public static final boolean DEFAULT_NAMESPACE_AWARE
public static final boolean DEFAULT_VALIDATION
public static DocumentBuilderFactory getDocumentBuilderFactory()
public static String toString(Document doc, boolean omitXMLDeclaration, boolean standalone, boolean indented, String encoding) throws TransformerException
TransformerExceptionpublic static String toString(Document doc) throws TransformerException
TransformerExceptiontoString(Document,Properties)public static String toString(Element element) throws ParserConfigurationException, TransformerException
ParserConfigurationExceptionTransformerExceptiontoString(Document)public static Document toDocument(String text) throws ParserConfigurationException, SAXException, IOException
public static Element toElement(String text) throws ParserConfigurationException, SAXException, IOException
public static Document toDocument(Element element) throws ParserConfigurationException, SAXException, IOException
public static String asString(Element element) throws IllegalArgumentException
element - IllegalArgumentExceptionasString(org.w3c.dom.Element,boolean)public static String asString(Element element, boolean trim) throws IllegalArgumentException
element - the containertrim - true if text should be trimmed before returning resultIllegalArgumentException - if the element content is mixed or nullpublic static Element getUniqueChild(Element element, boolean strict) throws IllegalArgumentException, NoSuchElementException, TooManyElementException
element - the parent elementstrict - true if the element must be presentIllegalArgumentException - if an argument is nullNoSuchElementException - if strict is true and the element is not presentTooManyElementException - if more than one element is foundpublic static Element getUniqueChild(Element element, String name, boolean strict) throws IllegalArgumentException, NoSuchElementException, TooManyElementException
element - the parent elementname - the child namestrict - if the child must be presentIllegalArgumentException - if an argument is nullNoSuchElementException - if strict is true and the element is not presentTooManyElementException - if more than one element is foundpublic static Element getUniqueChild(Element element, String uri, String name, boolean strict) throws IllegalArgumentException, NoSuchElementException, TooManyElementException
element - the parent elementname - the child nameuri - the child uristrict - if the child must be presentIllegalArgumentException - if an argument is nullNoSuchElementException - if strict is true and the element is not presentTooManyElementException - if more than one element is foundpublic static Iterator<Element> getChildrenIterator(Element element) throws IllegalArgumentException
element - the parent elementIllegalArgumentException - if the element is null or the name is nullpublic static Iterator<Element> getChildrenIterator(Element element, String name) throws IllegalArgumentException
element - the parent elementname - the child namesIllegalArgumentException - if the element is null or the name is nullpublic static Iterator<Element> getChildrenIterator(Element element, String uri, String name) throws IllegalArgumentException
element - the parent elementuri - the children uriname - the children nameIllegalArgumentException - if the element is null or the name is nullpublic static List<Element> getChildren(Element element) throws IllegalArgumentException
element - the parent elementIllegalArgumentException - if the element is null or the name is nullpublic static List<Element> getChildren(Element element, String name) throws IllegalArgumentException
element - the parent elementname - the child namesIllegalArgumentException - if the element is null or the name is nullpublic static List<Element> getChildren(Element element, String uri, String name) throws IllegalArgumentException
Return all the children of the given element having the optionally specified name and the namespace URI.
If the URI is specified then the element must have the same URI namespace in order to be included otherwise it will be included. If the URI is specified the name matching will be done against the element local name otherwise it will be done against the element tag name.
If the name is specified then the element must have the same tag name or the same local name to be retained otherwise it will be included.
The resulting element collection can be safely modified.
element - the parent elementuri - the children uriname - the children nameIllegalArgumentException - if the element is nullpublic static <T extends Node> List<T> getChildren(Node node, XMLTools.Filter<T> filter) throws IllegalArgumentException
Return all the children of the given node that match the provided filter.
The resulting element collection can be safely modified.
node - the parent elementfilter - the filterIllegalArgumentException - if the element is nullpublic static XMLTools.Filter<Element> byName(String uri, Set<String> names)
public static XMLTools.Filter<Element> byName(String uri, String name)
public static Properties loadXMLProperties(Element propertiesElt)
public static Properties loadXMLProperties(Document doc)
Copyright © 2025 JBoss by Red Hat. All Rights Reserved.