gov.llnl.babel.xml
public class XMLUtilities extends java.lang.Object
XMLUtiliites
is a collection of common
XML utility functions. All methods are declared as static. This
class is the primary interface to the XML parsers. The current
implementation uses the Xerces parsers from the Apache project.Constructor and Description |
---|
XMLUtilities() |
Modifier and Type | Method and Description |
---|---|
static org.w3c.dom.Document |
checkXML(java.lang.String frag)
Check whether the XML fragment is well-formed.
|
static org.w3c.dom.Node |
cloneDOM(org.w3c.dom.Node node,
org.w3c.dom.Document document)
Recursively copy the DOM tree using the specified document as the
root document factory.
|
static javax.xml.parsers.DocumentBuilder |
createDocBuilder() |
static java.lang.String |
decodeXMLString(java.lang.String s)
Transform &, < > " back into &,<,>,".
|
static java.lang.String |
encodeXMLString(java.lang.String s)
Normalize an XML string by replacing less than, greater than,
ampersand, and double quote by their XML entity representatives.
|
static java.lang.String |
formatChildren(org.w3c.dom.Node root)
Return a string representation of the XML DOM document under the
specified element root.
|
static java.lang.String |
getXMLString(org.w3c.dom.Node node)
Return a string representation of the XML DOM document.
|
static boolean |
isWhitespace(java.lang.String s)
Return whether the string contains only whitespace.
|
static org.w3c.dom.Element |
lookupElement(org.w3c.dom.Element e,
java.lang.String name)
Search the children of the specified parent element and return the
first element that matches the specified element name.
|
static org.w3c.dom.Document |
parse(org.xml.sax.InputSource is,
org.xml.sax.EntityResolver er)
Parse and validate the XML document represented by the specified
input source.
|
static org.w3c.dom.Document |
parse(java.lang.String uri)
Parse and validate the XML document represented by the string URI.
|
static java.lang.String |
trimWhiteSpaceLines(java.lang.String s)
Remove white space lines from the beginning and end of the string.
|
static org.w3c.dom.Document |
validateXML(java.lang.String dtdPublic,
java.lang.String dtdFile,
org.xml.sax.EntityResolver er,
java.lang.String start,
java.lang.String frag)
Validate the provided XML fragment with the specified start element
against the DTD public identifier.
|
static void |
writeDOM(org.w3c.dom.Node node,
java.io.PrintWriter writer)
Recursively write the XML DOM representation into a print writer
output stream.
|
public static javax.xml.parsers.DocumentBuilder createDocBuilder()
public static org.w3c.dom.Document parse(java.lang.String uri) throws java.io.IOException, org.xml.sax.SAXException
IOException
will be thrown if the supplied URI is
not valid. A SAXException
will be thrown if there was
an error parsing the XML. The return value is the DOM representation
of the parsed document.java.io.IOException
org.xml.sax.SAXException
public static org.w3c.dom.Document parse(org.xml.sax.InputSource is, org.xml.sax.EntityResolver er) throws java.io.IOException, org.xml.sax.SAXException
IOException
will be thrown
if the input source is not valid and a SAXException
will be thrown if there is an error parsing the XML. The return
value is the DOM representation of the parsed document.java.io.IOException
org.xml.sax.SAXException
public static org.w3c.dom.Document checkXML(java.lang.String frag)
public static org.w3c.dom.Document validateXML(java.lang.String dtdPublic, java.lang.String dtdFile, org.xml.sax.EntityResolver er, java.lang.String start, java.lang.String frag)
public static java.lang.String encodeXMLString(java.lang.String s)
public static java.lang.String decodeXMLString(java.lang.String s)
public static org.w3c.dom.Element lookupElement(org.w3c.dom.Element e, java.lang.String name)
public static org.w3c.dom.Node cloneDOM(org.w3c.dom.Node node, org.w3c.dom.Document document)
public static void writeDOM(org.w3c.dom.Node node, java.io.PrintWriter writer)
public static java.lang.String getXMLString(org.w3c.dom.Node node)
public static java.lang.String formatChildren(org.w3c.dom.Node root)
public static java.lang.String trimWhiteSpaceLines(java.lang.String s)
public static boolean isWhitespace(java.lang.String s)