|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object edu.northwestern.at.utils.xml.DOMUtils
public class DOMUtils
XML DOM utilities.
Method Summary | |
---|---|
static java.lang.String |
getAllText(org.w3c.dom.Node node)
Gets all the text for a node. |
static org.w3c.dom.Element |
getChild(org.w3c.dom.Node node,
java.lang.String name)
Gets a child element of a node by name. |
static org.w3c.dom.Element |
getChild(org.w3c.dom.Node node,
java.lang.String name,
java.lang.String attrName,
java.lang.String attrValue)
Gets a child element of a node by name and attribute value. |
static java.util.ArrayList |
getChildren(org.w3c.dom.Node node,
java.lang.String name)
Gets the child elements of a node by name. |
static java.util.ArrayList |
getChildren(org.w3c.dom.Node node,
java.lang.String name,
java.lang.String attrName,
java.lang.String attrValue)
Gets the child elements of a node by name and attribute value. |
static org.w3c.dom.Element |
getDescendant(org.w3c.dom.Node node,
java.lang.String path)
Gets a descendant element of a node. |
static java.util.ArrayList |
getDescendants(org.w3c.dom.Node node,
java.lang.String path)
Gets descendant elements of a node. |
static org.w3c.dom.Element |
getLastChild(org.w3c.dom.Node node,
java.lang.String name)
Gets the last child element of a node by name. |
static java.lang.String |
getText(org.w3c.dom.Node node)
Gets text for a node. |
static org.w3c.dom.Document |
newDocument()
Creates a new empty DOM document. |
static boolean |
nodeHasChild(org.w3c.dom.Node node,
java.lang.String name)
Checks to see if a node has a child of some name. |
static boolean |
nodeHasDescendant(org.w3c.dom.Node node,
java.lang.String name)
Checks to see if a node has a descendant of some name. |
static boolean |
nodeHasDescendant(org.w3c.dom.Node node,
java.lang.String[] names1,
java.lang.String[] names2)
Checks to see if a node has a descendant node of some name, other than those in children of some other name. |
static boolean |
nodeIsOrHasChild(org.w3c.dom.Node node,
java.lang.String name)
Checks to see if a node has a given name or has a child of the given name. |
static boolean |
nodeIsOrHasDescendant(org.w3c.dom.Node node,
java.lang.String name)
Checks to see if a node has a given name or has a descendant of the given name. |
static org.w3c.dom.Document |
parse(java.io.File file)
Parses an XML file. |
static org.w3c.dom.Document |
parse(java.lang.String path)
Parses an XML file. |
static org.w3c.dom.Document |
parse(java.net.URL url)
Parses XML document from URL. |
static void |
save(org.w3c.dom.Document document,
java.lang.String path)
Saves a DOM document to an XML file in utf-8. |
static void |
setText(org.w3c.dom.Node node,
java.lang.String text)
Sets text for a node. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static org.w3c.dom.Document parse(java.io.File file) throws java.io.IOException, javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException
file
- File.
java.lang.Exception
java.io.IOException
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
public static org.w3c.dom.Document parse(java.lang.String path) throws java.io.IOException, javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException
path
- File path.
java.lang.Exception
java.io.IOException
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
public static org.w3c.dom.Document parse(java.net.URL url) throws java.io.IOException, javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException
url
- URL.
java.lang.Exception
java.io.IOException
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
public static org.w3c.dom.Element getChild(org.w3c.dom.Node node, java.lang.String name)
node
- Node.name
- Name.
public static org.w3c.dom.Element getLastChild(org.w3c.dom.Node node, java.lang.String name)
node
- Node.name
- Name.
public static org.w3c.dom.Element getChild(org.w3c.dom.Node node, java.lang.String name, java.lang.String attrName, java.lang.String attrValue)
node
- Node.name
- Name.attrName
- Attribute name.attrValue
- Attribute value.
public static java.lang.String getText(org.w3c.dom.Node node)
node
- Node.
public static void setText(org.w3c.dom.Node node, java.lang.String text)
Sets the value of the first child text node, if any.
node
- Node.text
- New text for the node. public static java.lang.String getAllText(org.w3c.dom.Node node)
node
- Node.
public static java.util.ArrayList getChildren(org.w3c.dom.Node node, java.lang.String name)
node
- Node.name
- Name.
public static java.util.ArrayList getChildren(org.w3c.dom.Node node, java.lang.String name, java.lang.String attrName, java.lang.String attrValue)
node
- Node.name
- Name.attrName
- Attribute name.attrValue
- Attribute value.
public static org.w3c.dom.Element getDescendant(org.w3c.dom.Node node, java.lang.String path)
node
- Node.path
- Path to descendant, using tag names of child
elements separated by "/".
public static java.util.ArrayList getDescendants(org.w3c.dom.Node node, java.lang.String path)
node
- Node.path
- Path to descendants, using tag names of child
elements separated by "/".
public static org.w3c.dom.Document newDocument() throws javax.xml.parsers.ParserConfigurationException
javax.xml.parsers.ParserConfigurationException
public static void save(org.w3c.dom.Document document, java.lang.String path) throws javax.xml.transform.TransformerException, java.io.IOException
document
- DOM document.path
- Output file path.
TransformerException,
- IOException
javax.xml.transform.TransformerException
java.io.IOException
public static boolean nodeHasChild(org.w3c.dom.Node node, java.lang.String name)
node
- Node.name
- Name.
public static boolean nodeIsOrHasChild(org.w3c.dom.Node node, java.lang.String name)
node
- Node.name
- Name.
public static boolean nodeHasDescendant(org.w3c.dom.Node node, java.lang.String name)
node
- Node.name
- Name.
public static boolean nodeIsOrHasDescendant(org.w3c.dom.Node node, java.lang.String name)
node
- Node.name
- Name.
public static boolean nodeHasDescendant(org.w3c.dom.Node node, java.lang.String[] names1, java.lang.String[] names2)
node
- Nodenames1
- Array of names to include.names2
- Array of names to exclude.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |