java.lang.Object
com.aoapps.lang.xml.XmlUtils
Utilities that help when working with XML.
- Author:
- AO Industries, Inc.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The number of space characters per indentation level. -
Method Summary
Modifier and TypeMethodDescriptionstatic 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
Deprecated.static boolean
isValidName
(String name) Makes sure a valid Name.static boolean
isValidName
(String name, int begin, int end) Makes sure a valid Name.iterableChildElementsByTagName
(Element element, String childTagName) Iterates the children of the given element, returning only returning child elements of the given name.iterableElements
(NodeList nodeList) Iterates over a NodeList, only returning Elements.iterableNodes
(NodeList nodeList) Iterates over a NodeList.static Document
parseXml
(InputStream in) Parses an XML DOM from an input stream.static Document
Fetches and parses an XML DOM from a URL.static String
Deprecated.UsetoString(org.w3c.dom.Node)
instead.static String
-
Field Details
-
INDENT_SPACES
public static final int INDENT_SPACESThe number of space characters per indentation level.- See Also:
-
-
Method Details
-
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
Iterates over a NodeList. -
iterableElements
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
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
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:
-
toString
Deprecated.UsetoString(org.w3c.dom.Node)
instead.- Throws:
TransformerException
-
toString
- Throws:
TransformerException
-
isNameStartChar
public static boolean isNameStartChar(int codePoint) -
isNameChar
public static boolean isNameChar(int codePoint) -
isValidName
Makes sure a valid Name. -
isValidName
Makes sure a valid Name. -
isValidId
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
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)
-
isValidName(java.lang.String)
, since "Values of type ID MUST match the Name production."