So, to search for the /html/head element,
Document doc = new SAXReader().read("http://www.dom4j.org/");
Element htmlElem = doc.getRootElement();
Element headElem = htmlElem.element("head");
if (headElem != null) {
// node exists
}
This is more efficient, but requires you to know the document structure beforehand. Use XPath to either save yourself coding when performance isn't an issue, or when you need to be able to search for an arbitrary node.
christian.
On Wednesday, November 19, 2003, at 12:39 AM, David Thielen wrote:
----- Original Message -----
From: David Thielen
To: [EMAIL PROTECTED]
Sent: Sunday, November 16, 2003 2:59 PM
Subject: Re: [dom4j-user] [dom4j] - Does node exist
Actually this doesn't always work either. The best I have some up with is:
node.selectNodes(text).size() > 0
which I am assuming is not very efficient.
Is there a better way????
thanks - dave
----- Original Message -----
From: David Thielen
To: [EMAIL PROTECTED]
Sent: Sunday, November 16, 2003 1:45 PM
Subject: [dom4j-user] [dom4j] - Does node exist
Hi;
What is the most efficient way to determine if a node exists. The only way I have founs so far is:
if (node.matches(text))
where text is the xpath to the node I am looking for and node is a Node I start the search from.
thanks - dave