public class XmlUtils
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
XmlUtils.NodeProcessor<T> |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
getAttributeValue(org.w3c.dom.Node node,
java.lang.String attributeName) |
static java.lang.Integer |
getAttributeValueAsInt(org.w3c.dom.Node node,
java.lang.String attributeName) |
static <T> T |
getFirstMatchFromDocument(org.w3c.dom.Document vastDoc,
java.lang.String elementName,
java.lang.String attributeName,
java.lang.String attributeValue,
XmlUtils.NodeProcessor<T> nodeProcessor)
Get first matching data from a Document]'s elements that match the {@code elementName},
{@code attributeName}, and {@code attributeValue} filters.
|
static org.w3c.dom.Node |
getFirstMatchingChildNode(org.w3c.dom.Node node,
java.lang.String nodeName)
Gets the first direct child of the given node with a node named
nodeName . |
static org.w3c.dom.Node |
getFirstMatchingChildNode(org.w3c.dom.Node node,
java.lang.String nodeName,
java.lang.String attributeName,
java.util.List<java.lang.String> attributeValues)
Gets the first direct child of the given node with a node named
nodeName that has an
attribute named attributeName with a value that matches one of attributeValues . |
static java.lang.String |
getFirstMatchingStringData(org.w3c.dom.Document vastDoc,
java.lang.String elementName) |
static java.lang.String |
getFirstMatchingStringData(org.w3c.dom.Document vastDoc,
java.lang.String elementName,
java.lang.String attributeName,
java.lang.String attributeValue) |
static <T> java.util.List<T> |
getListFromDocument(org.w3c.dom.Document vastDoc,
java.lang.String elementName,
java.lang.String attributeName,
java.lang.String attributeValue,
XmlUtils.NodeProcessor<T> nodeProcessor)
Get a list of data from a Document]'s elements that match the {@code elementName},
{@code attributeName}, and {@code attributeValue} filters.
|
static java.util.List<org.w3c.dom.Node> |
getMatchingChildNodes(org.w3c.dom.Node node,
java.lang.String nodeName)
Return children of the
node parameter with a matching nodeName . |
static java.util.List<org.w3c.dom.Node> |
getMatchingChildNodes(org.w3c.dom.Node node,
java.lang.String nodeName,
java.lang.String attributeName,
java.util.List<java.lang.String> attributeValues)
Return children of the
node parameter with a matching nodeName &
attributeName that matches at least one of the passed-in attributeValues . |
static java.util.List<org.w3c.dom.Node> |
getNodesWithElementAndAttribute(org.w3c.dom.Document vastDoc,
java.lang.String elementName,
java.lang.String attributeName,
java.lang.String attributeValue) |
static java.lang.String |
getNodeValue(org.w3c.dom.Node node) |
static java.util.List<java.lang.String> |
getStringDataAsList(org.w3c.dom.Document vastDoc,
java.lang.String elementName) |
static java.util.List<java.lang.String> |
getStringDataAsList(org.w3c.dom.Document vastDoc,
java.lang.String elementName,
java.lang.String attributeName,
java.lang.String attributeValue) |
static boolean |
nodeMatchesAttributeFilter(org.w3c.dom.Node node,
java.lang.String attributeName,
java.util.List<java.lang.String> attributeValues)
Returns
true iff the node has the attribute attributeName with a value that
matches one of attributeValues . |
public static org.w3c.dom.Node getFirstMatchingChildNode(org.w3c.dom.Node node, java.lang.String nodeName)
nodeName
.
Only direct children are checked.public static org.w3c.dom.Node getFirstMatchingChildNode(org.w3c.dom.Node node, java.lang.String nodeName, java.lang.String attributeName, java.util.List<java.lang.String> attributeValues)
nodeName
that has an
attribute named attributeName
with a value that matches one of attributeValues
.
Only direct children are checked.nodeName
- matching nodes must have this name.attributeName
- matching nodes must have an attribute with this name.
Use null to match nodes with any attributes.attributeValues
- all matching child nodes' matching attribute will have a value that
matches one of these values. Use null to match nodes with any attribute
value.public static java.util.List<org.w3c.dom.Node> getMatchingChildNodes(org.w3c.dom.Node node, java.lang.String nodeName)
node
parameter with a matching nodeName
.node
- the root node to look beneath.nodeName
- all child nodes will match this element.public static java.util.List<org.w3c.dom.Node> getMatchingChildNodes(org.w3c.dom.Node node, java.lang.String nodeName, java.lang.String attributeName, java.util.List<java.lang.String> attributeValues)
node
parameter with a matching nodeName
&
attributeName
that matches at least one of the passed-in attributeValues
.
If attributeValues
is empty, no nodes will match. To match names only,
pass null for both attributeName
and attributeValues
.node
- the root node to look beneath.nodeName
- all child nodes will match this element.attributeName
- all matching child nodes will have an attribute of this name.attributeValues
- all matching child nodes' matching attribute will have a value that
matches one of these values.public static boolean nodeMatchesAttributeFilter(org.w3c.dom.Node node, java.lang.String attributeName, java.util.List<java.lang.String> attributeValues)
true
iff the node has the attribute attributeName
with a value that
matches one of attributeValues
.public static java.lang.String getNodeValue(org.w3c.dom.Node node)
public static java.lang.Integer getAttributeValueAsInt(org.w3c.dom.Node node, java.lang.String attributeName)
public static java.lang.String getAttributeValue(org.w3c.dom.Node node, java.lang.String attributeName)
public static <T> java.util.List<T> getListFromDocument(org.w3c.dom.Document vastDoc, java.lang.String elementName, java.lang.String attributeName, java.lang.String attributeValue, XmlUtils.NodeProcessor<T> nodeProcessor)
vastDoc
- The Document
we wish to extract data from.elementName
- Only elements with this name are processed.attributeName
- Only elements with this attribute are processed.attributeValue
- Only elements whose attribute with attributeName matches this value are processed.nodeProcessor
- Takes matching nodes and produces output data for that node.List<T>
with processed node data.public static <T> T getFirstMatchFromDocument(org.w3c.dom.Document vastDoc, java.lang.String elementName, java.lang.String attributeName, java.lang.String attributeValue, XmlUtils.NodeProcessor<T> nodeProcessor)
vastDoc
- The Document
we wish to extract data from.elementName
- Only elements with this name are processed.attributeName
- Only elements with this attribute are processed.attributeValue
- Only elements whose attribute with attributeName matches this value are processed.nodeProcessor
- Takes matching nodes and produces output data for that node.<T>
from first node that matches.public static java.lang.String getFirstMatchingStringData(org.w3c.dom.Document vastDoc, java.lang.String elementName)
public static java.lang.String getFirstMatchingStringData(org.w3c.dom.Document vastDoc, java.lang.String elementName, java.lang.String attributeName, java.lang.String attributeValue)
public static java.util.List<java.lang.String> getStringDataAsList(org.w3c.dom.Document vastDoc, java.lang.String elementName)
public static java.util.List<java.lang.String> getStringDataAsList(org.w3c.dom.Document vastDoc, java.lang.String elementName, java.lang.String attributeName, java.lang.String attributeValue)
public static java.util.List<org.w3c.dom.Node> getNodesWithElementAndAttribute(org.w3c.dom.Document vastDoc, java.lang.String elementName, java.lang.String attributeName, java.lang.String attributeValue)