|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.abstractics.utils.xml.DOMUtils
Various utility methods to deal with parsing XML into Document Object Models,
getting values from a DOM, and transforming a DOM back into XML.
All parsing activities rely on the JDK
javax.xml.parsers.DocumentBuilderFactory for parsing.
All transformation activities rely on the JDK
javax.xml.transform.TransformerFactory for transformation.
Method Summary | |
static org.w3c.dom.Element[] |
getDirectChildren(org.w3c.dom.Node node)
Returns all direct children of the given node (children where type = Node.ELEMENT_NODE). |
static org.w3c.dom.Element[] |
getDirectChildrenOfName(java.lang.String nodeName,
org.w3c.dom.Node node)
Returns any direct children of the given node (children where type = Node.ELEMENT_NODE) that have the name specified. |
static org.w3c.dom.Element |
getElement(org.w3c.dom.Node startNode,
java.lang.String path)
Given a starting node and a "path" this method will return the element at the end of that path. The path is an XPath-ish type string consisting of sub-element names separated by a forward slash. |
static java.lang.String |
getText(org.w3c.dom.Node node)
Returns the node value of the first Node.TEXT_NODE child
of the given node. |
static java.lang.String |
getValue(org.w3c.dom.Node startNode,
java.lang.String path)
Given a starting node and a "path" this method will return the text at the end of that path. The path is an XPath-ish type string consisting of sub-element names separated by a forward slash. |
static java.lang.String[] |
getValueNames(org.w3c.dom.Node node)
Given a Node, this method returns all of the attribute names that are available for it (non-null values). |
static org.w3c.dom.Document |
parseDOM(java.io.File file)
Given a file containing XML, this method parses it into a DOM Document |
static org.w3c.dom.Document |
parseDOM(java.io.InputStream is)
Given an InputStream of XML, this method parses it into a DOM Document |
static org.w3c.dom.Document |
parseDOM(java.io.Reader reader)
Given a Reader of XML, this method parses it into a DOM Document |
static org.w3c.dom.Document |
parseDOM(java.lang.String xml)
Given a String containing XML, this method parses it into a DOM Document |
static java.lang.String |
transformToXmlString(org.w3c.dom.Node node)
Returns a String that contains XML for the given Node |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public static java.lang.String getValue(org.w3c.dom.Node startNode, java.lang.String path)
<element foo="value" /> <element><foo>value</foo></element>
startNode
- The node to start frompath
- A simple XPath-ish descriptor for what to return.
public static org.w3c.dom.Element getElement(org.w3c.dom.Node startNode, java.lang.String path)
startNode
- The node to start frompath
- A simple XPath-ish descriptor for what to return.
public static org.w3c.dom.Document parseDOM(java.io.File file) throws XmlException, java.io.FileNotFoundException
file
- File object pointing to an XML file
XmlException
- Thrown if there is an error in parsing
java.io.FileNotFoundException
- Thrown if the given file cannot be found
java.lang.NullPointerException
- Thrown if the File is nullpublic static org.w3c.dom.Document parseDOM(java.lang.String xml) throws XmlException
xml
- String containing XML
XmlException
- Thrown if there is an error in parsing
java.lang.NullPointerException
- Thrown if the String is nullpublic static java.lang.String transformToXmlString(org.w3c.dom.Node node) throws XmlException
node
- Node to transform
XmlException
- Thrown if there is a parsing/transforming exceptionpublic static org.w3c.dom.Element[] getDirectChildrenOfName(java.lang.String nodeName, org.w3c.dom.Node node)
nodeName
- node
-
public static org.w3c.dom.Element[] getDirectChildren(org.w3c.dom.Node node)
node
-
public static java.lang.String getText(org.w3c.dom.Node node)
Node.TEXT_NODE
child
of the given node. Returns null if not found. Empty strings are also
returned as null.
node
-
public static java.lang.String[] getValueNames(org.w3c.dom.Node node)
<element foo="value" /> <element><foo>value</foo></element>
node
-
public static org.w3c.dom.Document parseDOM(java.io.InputStream is) throws XmlException
is
-
XmlException
- Thrown if there are parsing errors
java.lang.NullPointerException
- Thrown if the InputStream is nullpublic static org.w3c.dom.Document parseDOM(java.io.Reader reader) throws XmlException
reader
- Reader object that points to a XML source
XmlException
- Thrown if there is an error in parsing
java.lang.NullPointerException
- Thrown if the InputStream is null
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |