@Immutable public final class XMLHelper extends Object
| Modifier and Type | Method and Description |
|---|---|
static void |
append(Node aParentNode,
Collection<?> aNodesToAppend) |
static Node |
append(Node aParentNode,
Object aChild) |
static com.helger.commons.filter.IFilter<Element> |
filterElementWithNamespace() |
static com.helger.commons.filter.IFilter<Element> |
filterElementWithNamespace(String sNamespaceURI) |
static com.helger.commons.filter.IFilter<Element> |
filterElementWithNamespaceAndLocalName(String sNamespaceURI,
String sLocalName) |
static com.helger.commons.filter.IFilter<Element> |
filterElementWithoutNamespace() |
static com.helger.commons.filter.IFilter<Element> |
filterElementWithTagName(String sTagName) |
static com.helger.commons.filter.IFilter<Element> |
filterElementWithTagNameNoNS(String sTagName) |
static com.helger.commons.filter.IFilter<Node> |
filterNodeIsElement() |
static void |
forAllAttributes(Element aSrcNode,
BiConsumer<String,String> aConsumer) |
static void |
forAllAttributes(Element aSrcNode,
Consumer<Attr> aConsumer) |
static com.helger.commons.collection.ext.ICommonsList<Attr> |
getAllAttributesAsList(Element aSrcNode) |
static com.helger.commons.collection.ext.ICommonsOrderedMap<String,String> |
getAllAttributesAsMap(Element aSrcNode) |
static String |
getAttributeValue(Element aElement,
String sAttrName)
The latest version of XercesJ 2.9 returns an empty string for non existing
attributes.
|
static String |
getAttributeValue(Element aElement,
String sAttrName,
String sDefault)
The latest version of XercesJ 2.9 returns an empty string for non existing
attributes.
|
static String |
getAttributeValueNS(Element aElement,
String sNamespaceURI,
String sAttrName)
The latest version of XercesJ 2.9 returns an empty string for non existing
attributes.
|
static String |
getAttributeValueNS(Element aElement,
String sNamespaceURI,
String sAttrName,
String sDefault)
The latest version of XercesJ 2.9 returns an empty string for non existing
attributes.
|
static com.helger.commons.collection.iterate.IIterableIterator<Element> |
getChildElementIterator(Node aStartNode)
Get an iterator over all child elements.
|
static com.helger.commons.collection.iterate.IIterableIterator<Element> |
getChildElementIterator(Node aStartNode,
String sTagName)
Get an iterator over all child elements that have the desired tag name (but
potentially a namespace URI).
|
static com.helger.commons.collection.iterate.IIterableIterator<Element> |
getChildElementIteratorNoNS(Node aStartNode)
Get an iterator over all child elements that have no namespace.
|
static com.helger.commons.collection.iterate.IIterableIterator<Element> |
getChildElementIteratorNoNS(Node aStartNode,
String sTagName)
Get an iterator over all child elements that have no namespace and the
desired tag name.
|
static com.helger.commons.collection.iterate.IIterableIterator<Element> |
getChildElementIteratorNS(Node aStartNode,
String sNamespaceURI) |
static com.helger.commons.collection.iterate.IIterableIterator<Element> |
getChildElementIteratorNS(Node aStartNode,
String sNamespaceURI,
String sLocalName) |
static int |
getDirectChildElementCount(Element aParent) |
static int |
getDirectChildElementCount(Element aParent,
String sTagName) |
static int |
getDirectChildElementCountNoNS(Element aParent) |
static int |
getDirectChildElementCountNoNS(Element aParent,
String sTagName) |
static int |
getDirectChildElementCountNS(Element aParent,
String sNamespaceURI) |
static int |
getDirectChildElementCountNS(Element aParent,
String sNamespaceURI,
String sLocalName) |
static Element |
getDocumentElement(Node aNode) |
static String |
getElementName(Node aNode) |
static Element |
getFirstChildElement(Node aStartNode)
Get the first direct child element of the passed element.
|
static Element |
getFirstChildElementOfName(Node aStartNode,
String sTagName)
Search all child nodes of the given for the first element that has the
specified tag name.
|
static Element |
getFirstChildElementOfName(Node aStartNode,
String sNamespaceURI,
String sLocalName)
Search all child nodes of the given for the first element that has the
specified tag name.
|
static String |
getFirstChildText(Node aStartNode)
Get the content of the first Text child element of the passed element.
|
static int |
getLength(NodeList aNL) |
static String |
getNamespaceURI(Node aNode) |
static Document |
getOwnerDocument(Node aNode)
Get the owner document of the passed node.
|
static String |
getPathToNode(Node aNode)
Shortcut for
getPathToNode(Node, String) using "/" as the
separator. |
static String |
getPathToNode(Node aNode,
String sSep)
Get the path from root node to the passed node.
|
static String |
getPathToNode2(Node aNode)
Shortcut for
getPathToNode2(Node,String) using "/" as the
separator. |
static String |
getPathToNode2(Node aNode,
String sSep)
Get the path from root node to the passed node.
|
static QName |
getXMLNSAttrQName(String sNSPrefix)
Get the full qualified attribute name to use for the given namespace
prefix.
|
static boolean |
hasChildElementNodes(Node aStartNode)
Check if the passed node has at least one direct child element or not.
|
static boolean |
hasNamespaceURI(Node aNode,
String sNamespaceURI) |
static boolean |
hasNoNamespaceURI(Node aNode) |
static boolean |
isEmpty(NodeList aNL) |
static boolean |
isInlineNode(Node aNode)
Check if the passed node is a text node.
|
static void |
removeAllChildElements(Element aElement)
Remove all child nodes of the given node.
|
@Nullable public static Document getOwnerDocument(@Nullable Node aNode)
aNode - The node to get the document from. May be null.null if the passed node was null.public static boolean hasNamespaceURI(@Nullable Node aNode, @Nullable String sNamespaceURI)
public static boolean isInlineNode(@Nullable Node aNode)
Text (Text and CData) or EntityReference nodes.aNode - The node to be checked.true if the passed node is a text node,
false otherwise.@Nonnegative public static int getLength(@Nullable NodeList aNL)
@Nonnull public static com.helger.commons.filter.IFilter<Node> filterNodeIsElement()
@Nonnull public static com.helger.commons.filter.IFilter<Element> filterElementWithNamespace()
@Nonnull public static com.helger.commons.filter.IFilter<Element> filterElementWithoutNamespace()
@Nonnull public static com.helger.commons.filter.IFilter<Element> filterElementWithNamespace(@Nullable String sNamespaceURI)
@Nonnull public static com.helger.commons.filter.IFilter<Element> filterElementWithNamespaceAndLocalName(@Nullable String sNamespaceURI, @Nonnull @Nonempty String sLocalName)
@Nonnull public static com.helger.commons.filter.IFilter<Element> filterElementWithTagName(@Nonnull @Nonempty String sTagName)
@Nonnull public static com.helger.commons.filter.IFilter<Element> filterElementWithTagNameNoNS(@Nonnull @Nonempty String sTagName)
@Nullable public static Element getFirstChildElement(@Nonnull Node aStartNode)
aStartNode - The element to start searching.null if the passed element does not have any direct
child element.public static boolean hasChildElementNodes(@Nonnull Node aStartNode)
aStartNode - The parent element to be searched. May not be null.true if the passed node has at least one child
element, false otherwise.@Nullable public static Element getFirstChildElementOfName(@Nonnull Node aStartNode, @Nullable String sTagName)
aStartNode - The parent element to be searched. May not be null.sTagName - The tag name to search.null if the parent element has no such child element.@Nullable public static Element getFirstChildElementOfName(@Nonnull Node aStartNode, @Nullable String sNamespaceURI, @Nullable String sLocalName)
aStartNode - The parent element to be searched. May not be null.sNamespaceURI - Namespace URI to search. May be null.sLocalName - The tag name to search.null if the parent element has no such child element.public static void append(@Nonnull Node aParentNode, @Nonnull Collection<?> aNodesToAppend)
@Nonnegative public static int getDirectChildElementCount(@Nullable Element aParent)
@Nonnegative public static int getDirectChildElementCountNoNS(@Nullable Element aParent)
@Nonnegative public static int getDirectChildElementCount(@Nullable Element aParent, @Nonnull @Nonempty String sTagName)
@Nonnegative public static int getDirectChildElementCountNoNS(@Nullable Element aParent, @Nonnull @Nonempty String sTagName)
@Nonnegative public static int getDirectChildElementCountNS(@Nullable Element aParent, @Nullable String sNamespaceURI)
@Nonnegative public static int getDirectChildElementCountNS(@Nullable Element aParent, @Nullable String sNamespaceURI, @Nonnull @Nonempty String sLocalName)
@Nonnull public static com.helger.commons.collection.iterate.IIterableIterator<Element> getChildElementIterator(@Nullable Node aStartNode)
aStartNode - the parent element@Nonnull public static com.helger.commons.collection.iterate.IIterableIterator<Element> getChildElementIteratorNoNS(@Nullable Node aStartNode)
aStartNode - the parent element@Nonnull public static com.helger.commons.collection.iterate.IIterableIterator<Element> getChildElementIteratorNoNS(@Nullable Node aStartNode, @Nonnull @Nonempty String sTagName)
aStartNode - the parent elementsTagName - the name of the tag that is desiredIllegalArgumentException - if the passed tag name is null or empty@Nonnull public static com.helger.commons.collection.iterate.IIterableIterator<Element> getChildElementIterator(@Nullable Node aStartNode, @Nonnull @Nonempty String sTagName)
aStartNode - the parent elementsTagName - the name of the tag that is desiredIllegalArgumentException - if the passed tag name is null or empty@Nonnull public static com.helger.commons.collection.iterate.IIterableIterator<Element> getChildElementIteratorNS(@Nullable Node aStartNode, @Nullable String sNamespaceURI)
@Nonnull public static com.helger.commons.collection.iterate.IIterableIterator<Element> getChildElementIteratorNS(@Nullable Node aStartNode, @Nullable String sNamespaceURI, @Nonnull @Nonempty String sLocalName)
@Nonnull public static String getPathToNode(@Nonnull Node aNode)
getPathToNode(Node, String) using "/" as the
separator.aNode - The node to check.null path.@Nonnull public static String getPathToNode(@Nonnull Node aNode, @Nonnull String sSep)
aNode - The node to start. May not be null.sSep - The separator string to use. May not be null.@Nonnull public static String getPathToNode2(@Nonnull Node aNode)
getPathToNode2(Node,String) using "/" as the
separator.aNode - The node to check.null path.@Nonnull public static String getPathToNode2(@Nonnull Node aNode, @Nonnull String sSep)
aNode - The node to start. May not be null.sSep - The separator string to use. May not be null.public static void removeAllChildElements(@Nonnull Element aElement)
aElement - The element whose children are to be removed.@Nullable public static String getFirstChildText(@Nullable Node aStartNode)
aStartNode - the element to scan for a TextNode childnull if the element contains no text node as child@Nullable public static String getAttributeValue(@Nonnull Element aElement, @Nonnull String sAttrName)
aElement - the source element to get the attribute fromsAttrName - the name of the attribute to querynull if the attribute does not exists, the string
value otherwise@Nullable public static String getAttributeValue(@Nonnull Element aElement, @Nonnull String sAttrName, @Nullable String sDefault)
aElement - the source element to get the attribute from. May not be
null.sAttrName - the name of the attribute to query. May not be null.sDefault - the value to be returned if the attribute is not present.@Nullable public static String getAttributeValueNS(@Nonnull Element aElement, @Nullable String sNamespaceURI, @Nonnull String sAttrName)
aElement - the source element to get the attribute fromsNamespaceURI - The namespace URI of the attribute to retrieve. May be
null.sAttrName - the name of the attribute to querynull if the attribute does not exists, the string
value otherwise@Nullable public static String getAttributeValueNS(@Nonnull Element aElement, @Nullable String sNamespaceURI, @Nonnull String sAttrName, @Nullable String sDefault)
aElement - the source element to get the attribute from. May not be
null.sNamespaceURI - The namespace URI of the attribute to retrieve. May be
null.sAttrName - the name of the attribute to query. May not be null.sDefault - the value to be returned if the attribute is not present.@Nonnull @ReturnsMutableCopy public static com.helger.commons.collection.ext.ICommonsList<Attr> getAllAttributesAsList(@Nullable Element aSrcNode)
@Nonnull @ReturnsMutableCopy public static com.helger.commons.collection.ext.ICommonsOrderedMap<String,String> getAllAttributesAsMap(@Nullable Element aSrcNode)
public static void forAllAttributes(@Nullable Element aSrcNode, @Nonnull Consumer<Attr> aConsumer)
public static void forAllAttributes(@Nullable Element aSrcNode, @Nonnull BiConsumer<String,String> aConsumer)
@Nonnull public static QName getXMLNSAttrQName(@Nullable String sNSPrefix)
xmlns or
{http://www.w3.org/2000/xmlns/}xmlns:foo.sNSPrefix - The namespace prefix to build the attribute name from. May be
null or empty.XMLConstants.DEFAULT_NS_PREFIX or null) than
"xmlns" is returned, else "xmlns:prefix" is returned.Copyright © 2014–2016 Philip Helger. All rights reserved.