|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.lenya.xml.DOMUtil
public class DOMUtil
This class is a utility class for miscellaneous DOM functions, similar to org.apache.cocoon.xml.dom.DOMUtil FIXME: Merge classes or extend functionality
Constructor Summary | |
---|---|
DOMUtil()
Ctor. |
Method Summary | |
---|---|
void |
addElement(org.w3c.dom.Document document,
java.lang.String xpath,
java.lang.String value)
Deprecated. See replacement code. |
org.w3c.dom.Document |
create(java.lang.String xml)
Deprecated. Use DocumentHelper.readDocument(java.lang.String) instead. |
org.w3c.dom.Node |
createNode(org.w3c.dom.Document document,
XPath xpath)
Deprecated. See replacement code. |
boolean |
elementExists(org.w3c.dom.Element element,
XPath xpath)
Deprecated. See replacement code. |
org.w3c.dom.Element[] |
getAllElements(org.w3c.dom.Document document,
XPath xpath)
Deprecated. Use XPathAPI.selectNodeList(org.w3c.dom.Node, java.lang.String)
instead. |
java.lang.String[] |
getAllElementValues(org.w3c.dom.Document document,
XPath xpath)
get all elements values from |xpath|, xpath has to start with the root node |
java.lang.String |
getAttributeValue(org.w3c.dom.Element element,
XPath xpath)
Deprecated. See replacement code. |
org.w3c.dom.Element |
getElement(org.w3c.dom.Element element,
XPath xpath)
Deprecated. Use XPathAPI.selectSingleNode(org.w3c.dom.Node, java.lang.String)
instead. |
java.lang.String |
getElementValue(org.w3c.dom.Document document,
XPath xpath)
Deprecated. Use instead. |
java.lang.String |
getElementValue(org.w3c.dom.Element element)
Deprecated. See replacement code. |
java.lang.String |
getElementValue(org.w3c.dom.Element element,
XPath xpath)
Deprecated. Use instead. |
static void |
main(java.lang.String[] args)
Main method, used to test the class. |
void |
replaceText(org.w3c.dom.Element element,
java.lang.String text)
This method removes all child nodes from an element and inserts a text node instead. |
org.w3c.dom.Element[] |
select(org.w3c.dom.Document document,
java.lang.String xpath)
Deprecated. Use XPathAPI.selectNodeList(org.w3c.dom.Node, java.lang.String)
instead. |
void |
setAttributeValue(org.w3c.dom.Document document,
java.lang.String xpath,
java.lang.String value)
Deprecated. See replacement code. |
void |
setElementValue(org.w3c.dom.Document document,
java.lang.String xpath,
java.lang.String value)
Deprecated. See replacement code. |
void |
setValue(org.w3c.dom.Document document,
XPath xpath,
java.lang.String value)
If the XPath expression denotes an element, the child nodes of this element are replaced by a single text node. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DOMUtil()
Method Detail |
---|
public static void main(java.lang.String[] args)
args
- The command line arguments.public org.w3c.dom.Document create(java.lang.String xml) throws java.lang.Exception
DocumentHelper.readDocument(java.lang.String)
instead.
xml
- The string.
java.lang.Exception
- if an error occurs.public org.w3c.dom.Element[] select(org.w3c.dom.Document document, java.lang.String xpath) throws java.lang.Exception
XPathAPI.selectNodeList(org.w3c.dom.Node, java.lang.String)
instead.
document
- The document.xpath
- The XPath.
java.lang.Exception
- if the XPath does not return a NodeList
consisting of elements.public void replaceText(org.w3c.dom.Element element, java.lang.String text)
This method removes all child nodes from an element and inserts a text node instead.
Caution: Child elements are removed as well!
element
- The element.text
- The string to insert as a text node.public java.lang.String getElementValue(org.w3c.dom.Document document, XPath xpath) throws java.lang.Exception
instead.
document
- The document.xpath
- The XPath of the element to resolve.
java.lang.Exception
- if an error occurs.public java.lang.String getElementValue(org.w3c.dom.Element element, XPath xpath) throws java.lang.Exception
instead.
element
- The element to resolve the XPath against.xpath
- The XPath of the element to resolve.
java.lang.Exception
- if an error occurs.public boolean elementExists(org.w3c.dom.Element element, XPath xpath) throws java.lang.Exception
Node node = XPathAPI.selectSingleNode(element, xPath);
if (node != null && node instanceof Element) {
exists = true;
}
java.lang.Exception
public org.w3c.dom.Element getElement(org.w3c.dom.Element element, XPath xpath) throws java.lang.Exception
XPathAPI.selectSingleNode(org.w3c.dom.Node, java.lang.String)
instead.
java.lang.Exception
public org.w3c.dom.Element[] getAllElements(org.w3c.dom.Document document, XPath xpath) throws java.lang.Exception
XPathAPI.selectNodeList(org.w3c.dom.Node, java.lang.String)
instead.
document
- a value of type 'Document'xpath
- a value of type 'XPath'
java.lang.Exception
- if an error occurspublic java.lang.String[] getAllElementValues(org.w3c.dom.Document document, XPath xpath) throws java.lang.Exception
document
- a value of type 'Document'xpath
- a value of type 'XPath'
java.lang.Exception
- if an error occurspublic java.lang.String getElementValue(org.w3c.dom.Element element) throws java.lang.Exception
element
- The element.
java.lang.Exception
- if an error occurs.
Replacement code:
Element element = (Element) XPathAPI.selectSingleNode(document, xPath);
String value = DocumentHelper.getSimpleElementText(element, "...");
public java.lang.String getAttributeValue(org.w3c.dom.Element element, XPath xpath) throws java.lang.Exception
element
- a value of type 'Element'xpath
- a value of type 'XPath'
Element element = (Element) XPathAPI.selectSingleNode(document, xPath);
String value = element.getAttribute("...");
java.lang.Exception
public void setElementValue(org.w3c.dom.Document document, java.lang.String xpath, java.lang.String value) throws java.lang.Exception
document
- a value of type 'Document'xpath
- a value of type 'String'value
- a value of type 'String'
java.lang.Exception
- if an error occurs
Replacement code:
Element element = (Element) XPathAPI.selectSingleNode(document, xPath);
DocumentHelper.setSimpleElementText(element, "...");
public void addElement(org.w3c.dom.Document document, java.lang.String xpath, java.lang.String value) throws java.lang.Exception
Element parent = (Element) XPathAPI.selectSingleNode(document, xPath);
Element child = NamespaceHelper.createElement("...", "...");
parent.appendChild(child);
java.lang.Exception
public void setAttributeValue(org.w3c.dom.Document document, java.lang.String xpath, java.lang.String value) throws java.lang.Exception
Element element = (Element) XPathAPI.selectSingleNode(document, xPath);
element.setAttribute("...", "...");
java.lang.Exception
public void setValue(org.w3c.dom.Document document, XPath xpath, java.lang.String value) throws java.lang.Exception
document
- The document to resolve the XPath against.xpath
- The XPath.value
- A string.
java.lang.Exception
- if an error occurs.public org.w3c.dom.Node createNode(org.w3c.dom.Document document, XPath xpath) throws java.lang.Exception
Element parent = XPathAPI.selectSingleNode(...);
Element child = document.createElementNS("http://...", "...");
parent.appendChild(child);
java.lang.Exception
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |