- java.lang.Object
-
- com.aoapps.lang.xml.XmlUtils
-
public final class XmlUtils extends Object
Utilities that help when working with XML.- Author:
- AO Industries, Inc.
-
-
Field Summary
Fields Modifier and Type Field Description static int
INDENT_SPACES
The number of space characters per indentation level.
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static StringBuilder
generateId(String template, String defaultId)
Generates a valid ID from an arbitrary string.static Element
getChildElementByTagName(Element element, String childTagName)
Gets the child element for a tag name ornull
if not found.static String
getChildTextContent(Element element, String childTagName)
Gets the text content of a child element for a tag name ornull
if not found.static boolean
isHyphen(int codePoint)
Convert a couple other types of hyphens.static boolean
isNameChar(int codePoint)
static boolean
isNameStartChar(int codePoint)
static boolean
isValidId(String id)
Deprecated.Please useisValidName(java.lang.String)
, since "Values of type ID MUST match the Name production."static boolean
isValidName(String name)
Makes sure a valid Name.static boolean
isValidName(String name, int begin, int end)
Makes sure a valid Name.static Iterable<Element>
iterableChildElementsByTagName(Element element, String childTagName)
Iterates the children of the given element, returning only returning child elements of the given name.static Iterable<Element>
iterableElements(NodeList nodeList)
Iterates over a NodeList, only returning Elements.static Iterable<Node>
iterableNodes(NodeList nodeList)
Iterates over a NodeList.static Document
parseXml(InputStream in)
Parses an XML DOM from an input stream.static Document
parseXml(URL url)
Fetches and parses an XML DOM from a URL.static String
toString(Document document)
Deprecated.UsetoString(org.w3c.dom.Node)
instead.static String
toString(Node node)
-
-
-
Field Detail
-
INDENT_SPACES
public static final int INDENT_SPACES
The number of space characters per indentation level.- See Also:
- Constant Field Values
-
-
Method Detail
-
parseXml
public static Document parseXml(URL url) throws IOException, ParserConfigurationException, SAXException
Fetches and parses an XML DOM from a URL. Uses the following XML security features:
-
parseXml
public static Document parseXml(InputStream in) throws IOException, ParserConfigurationException, SAXException
Parses an XML DOM from an input stream. Uses the following XML security features:
-
iterableNodes
public static Iterable<Node> iterableNodes(NodeList nodeList)
Iterates over a NodeList.
-
iterableElements
public static Iterable<Element> iterableElements(NodeList nodeList)
Iterates over a NodeList, only returning Elements.
-
iterableChildElementsByTagName
public static Iterable<Element> iterableChildElementsByTagName(Element element, String childTagName)
Iterates the children of the given element, returning only returning child elements of the given name.
-
getChildElementByTagName
public static Element getChildElementByTagName(Element element, String childTagName)
Gets the child element for a tag name ornull
if not found. Is an error if more than once child is found for the given name.- Throws:
IllegalStateException
- if there is more than one child element with the given name
-
getChildTextContent
public static String getChildTextContent(Element element, String childTagName)
Gets the text content of a child element for a tag name ornull
if not found. Is an error if more than once child is found for the given name.- Throws:
IllegalStateException
- if there is more than one child element with the given name- See Also:
getChildElementByTagName(org.w3c.dom.Element, java.lang.String)
-
toString
@Deprecated public static String toString(Document document) throws TransformerException
Deprecated.UsetoString(org.w3c.dom.Node)
instead.- Throws:
TransformerException
-
toString
public static String toString(Node node) throws TransformerException
- Throws:
TransformerException
-
isNameStartChar
public static boolean isNameStartChar(int codePoint)
-
isNameChar
public static boolean isNameChar(int codePoint)
-
isValidName
public static boolean isValidName(String name, int begin, int end)
Makes sure a valid Name.
-
isValidName
public static boolean isValidName(String name)
Makes sure a valid Name.
-
isValidId
@Deprecated public static boolean isValidId(String id)
Deprecated.Please useisValidName(java.lang.String)
, since "Values of type ID MUST match the Name production."Makes sure an ID is valid.
-
isHyphen
public static boolean isHyphen(int codePoint)
Convert a couple other types of hyphens. http://jkorpela.fi/dashes.html, Table 6-3.
-
generateId
public static StringBuilder generateId(String template, String defaultId)
Generates a valid ID from an arbitrary string.Strips all character not matching Names and Tokens: Name:
- Parameters:
template
- The preferred text to base the id ondefaultId
- The base used when template is unusable (must be a valid id or invalid ID's may be generated)
-
-