public class XmlUtils extends Object
Modifier and Type | Class and Description |
---|---|
static class |
XmlUtils.XmlRuntimeException
Represents exceptions that can occur while processing XML text.
|
Modifier and Type | Field and Description |
---|---|
static String |
XML_EXTENSION |
Constructor and Description |
---|
XmlUtils() |
Modifier and Type | Method and Description |
---|---|
static boolean |
attributeIsFalsey(Node node,
String name) |
static boolean |
attributeIsTruthy(Node node,
String name) |
static void |
ensureNotNull(Object node,
String tag) |
static String |
getAttribute(Node node,
String name)
Returns the value of the attribute of the given node with the given name.
|
static String |
getAttribute(Node node,
String name,
boolean required) |
static String |
getAttribute(Node node,
String name,
boolean required,
String defaultValue) |
static String |
getAttributeAny(Node node,
boolean required,
String... names)
Returns the value of the first attribute found with any of the given names, else null.
|
static String |
getAttributeAny(Node node,
String... names)
Returns the value of the first attribute found with any of the given names, else null.
|
static int |
getAttributeInt(Node node,
String name) |
static int |
getAttributeInt(Node node,
String name,
boolean required) |
static int |
getAttributeInt(Node node,
String name,
boolean required,
int defaultValue) |
static String |
getAttributeOrChild(Node node,
String name) |
static String |
getAttributeOrChild(Node node,
String name,
boolean required)
Returns the value of the attribute of the given node with the given name.
|
static List<String> |
getAttributes(Node node)
Returns all attributes of the given XML node as a list of name=value strings.
|
static Node |
getChildByTagName(Node node,
String element) |
static Node |
getChildByTagName(Node node,
String element,
boolean required) |
static Node |
getChildNode(Node node,
String element) |
static List<Node> |
getChildNodes(Node node,
String... elements) |
static List<Node> |
getChildrenByTagName(Node node,
String element) |
static List<Node> |
getChildrenByTagNames(Node node,
String... elements) |
static String |
getChildValue(Node node,
String element) |
static String |
getChildValue(Node node,
String element,
boolean required) |
static Element |
getElementByTagName(Document document,
String element) |
static String |
getTextContent(Node node) |
static String |
getTextContent(Node node,
boolean trim) |
static boolean |
hasAttribute(Node node,
String name)
Returns whether the given XML DOM node contains the given attribute.
|
static boolean |
hasAttributeAny(Node node,
String... names)
Returns the value of the first attribute found with any of the given names, else null.
|
static boolean |
hasAttributes(Node node,
String... names)
Returns whether the given XML DOM node contains all of the given attributes.
|
static void |
requireAttributes(Node node,
String... names)
Ensures that the given XML DOM node contains all of the given attributes.
|
static void |
setAttribute(Node node,
String name,
String value) |
static Node |
up(Node node,
String element) |
static void |
validate(String xmlFileName,
String schemaFileName) |
public static final String XML_EXTENSION
public static String getAttribute(Node node, String name)
node
- the XML node to examinename
- the attribute name for which to retrieve the valuepublic static String getAttribute(Node node, String name, boolean required, String defaultValue)
public static int getAttributeInt(Node node, String name, boolean required, int defaultValue)
public static String getAttributeAny(Node node, String... names)
node
- the XML node to examinepublic static String getAttributeAny(Node node, boolean required, String... names)
node
- the XML node to examinepublic static String getAttributeOrChild(Node node, String name, boolean required)
node
- the XML node to examinename
- the attribute name for which to retrieve the valuepublic static List<String> getAttributes(Node node)
node
- public static boolean hasAttribute(Node node, String name)
node
- the XML node to examinename
- an attribute name to checkpublic static boolean hasAttributeAny(Node node, String... names)
node
- the XML node to examinepublic static boolean hasAttributes(Node node, String... names)
node
- the XML node to examinenames
- a variable-length list of attribute names to checkpublic static void requireAttributes(Node node, String... names)
node
- the XML node to examinenames
- a variable-length list of attribute names to checkXMLStreamException
- if any attribute is not foundpublic static void validate(String xmlFileName, String schemaFileName) throws IOException, ParserConfigurationException, SAXException