public class XmlParseUtil
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
XmlParseUtil.LocalEntityResolver
An
EntityResolver implementation that resolves
entities using a selection of locally stored DTDs. |
static class |
XmlParseUtil.ThrowingErrorHandler
A simple
ErrorHandler implementation that always
throws the SAXParseException . |
Modifier and Type | Method and Description |
---|---|
static java.util.Map<java.lang.String,java.lang.String> |
getAllAttributes(org.w3c.dom.Element elem,
java.lang.String name)
Get the attribute values of a given name/value pair for
the first XML
org.w3c.dom.Element of given name. |
static java.util.List<java.lang.String> |
getAllElementsByTagName(org.w3c.dom.Element elem,
java.lang.String name)
Get a list of all child text Elements of given name directly
under a given
org.w3c.dom.Element . |
static java.lang.String |
getCdata(org.w3c.dom.Element elem)
Extracts the first CDATA child from the given
org.w3c.dom.Element . |
static java.lang.String |
getFirstAttribute(org.w3c.dom.Element elem,
java.lang.String name,
java.lang.String attrName)
Get the attribute value of a given attribute name for
the first XML
org.w3c.dom.Element of given name. |
static java.lang.String |
getFirstElementByTagName(org.w3c.dom.Element elem,
java.lang.String name)
Get text data of first XML
org.w3c.dom.Element of given name. |
static java.lang.String |
getOptionalElementByTagName(org.w3c.dom.Element elem,
java.lang.String name)
Get text data of an optional XML
org.w3c.dom.Element of given name. |
static org.w3c.dom.Document |
parse(java.io.InputStream in,
SAXParseErrorHandler errorHandler,
org.xml.sax.EntityResolver entityResolver)
Parse an input stream to a
org.w3c.dom.Document . |
static org.w3c.dom.Document |
parse(java.lang.String fileContent,
SAXParseErrorHandler errorHandler,
org.xml.sax.EntityResolver entityResolver)
Parse an XML String to a
org.w3c.dom.Document . |
static org.w3c.dom.Element |
parseAndGetRootElement(java.io.InputStream in,
java.lang.String rootTagName)
Get a root
org.w3c.dom.Element from an XML input stream. |
static org.w3c.dom.Element |
parseAndGetRootElement(java.lang.String xmlBody,
java.lang.String rootTagName)
Get a root
org.w3c.dom.Element from the XML request body. |
static void |
validateXhtml(java.lang.String formSnippet)
Parses a form snippet using the XHTML Strict DTD, the
appropriate HTML context, and a validating parser.
|
public static void validateXhtml(java.lang.String formSnippet) throws java.lang.Exception
formSnippet
- the form snippetjava.lang.Exception
- if an unexpected error occrspublic static org.w3c.dom.Document parse(java.lang.String fileContent, SAXParseErrorHandler errorHandler, org.xml.sax.EntityResolver entityResolver)
org.w3c.dom.Document
.fileContent
- the XML stringerrorHandler
- the error handle for SAX parserentityResolver
- the entity resolver to usenull
on errorpublic static org.w3c.dom.Element parseAndGetRootElement(java.lang.String xmlBody, java.lang.String rootTagName)
org.w3c.dom.Element
from the XML request body.xmlBody
- the XML request body as a StringrootTagName
- the root Element tag namenull
on errorpublic static org.w3c.dom.Document parse(java.io.InputStream in, SAXParseErrorHandler errorHandler, org.xml.sax.EntityResolver entityResolver)
org.w3c.dom.Document
.in
- the input streamerrorHandler
- the error handle for SAX parserentityResolver
- the entity resolver to usenull
on errorpublic static org.w3c.dom.Element parseAndGetRootElement(java.io.InputStream in, java.lang.String rootTagName)
org.w3c.dom.Element
from an XML input stream.in
- the input streamrootTagName
- the root Element tag namenull
on errorpublic static java.lang.String getFirstAttribute(org.w3c.dom.Element elem, java.lang.String name, java.lang.String attrName)
org.w3c.dom.Element
of given name.elem
- the parent XML Elementname
- the name of the child text ElementattrName
- the attribute namepublic static java.util.Map<java.lang.String,java.lang.String> getAllAttributes(org.w3c.dom.Element elem, java.lang.String name)
org.w3c.dom.Element
of given name.elem
- the parent XML Elementname
- the name of the child text Elementpublic static java.lang.String getOptionalElementByTagName(org.w3c.dom.Element elem, java.lang.String name)
org.w3c.dom.Element
of given name.
Note that this differs from getFirstElementByTagName(org.w3c.dom.Element, java.lang.String)
in how it
handles missing elements vs. empty elements. Specifically, if the named
element does not exist, this returns null
. However, if the named
element does exist, but is empty (<tag></tag> or
<tag/>), this returns the empty string. In both cases
getFirstElementByTagName
would return null
.
elem
- the parent XML Elementname
- the name of the child text Elementnull
if the named element does not exist.
Returns the empty string if the named element exists, but is empty.public static java.lang.String getFirstElementByTagName(org.w3c.dom.Element elem, java.lang.String name)
org.w3c.dom.Element
of given name.elem
- the parent XML Elementname
- the name of the child text Elementpublic static java.util.List<java.lang.String> getAllElementsByTagName(org.w3c.dom.Element elem, java.lang.String name)
org.w3c.dom.Element
.elem
- the parent Elementname
- the given name of searched child Elementspublic static java.lang.String getCdata(org.w3c.dom.Element elem)
org.w3c.dom.Element
.elem
- the parent Elementnull
if none
found