[jdom-interest] Searching a JDOM document

Paul Chapman chapman at zemsys.com
Wed Aug 28 00:18:36 PDT 2002


However be warned - I have recently been doing exactly the same
thing and the Jaxen XPath approach is MUCH slower (30x in fact)

Of course the XPath approach gives you the prospect of a lot more
functionality with no code on your part. Depends how critical it
is for you.

Frank Sauer wrote:

> try Jaxen and an XPath expression like //elementName
> 
> -----Original Message-----
> From: Hushagen, Michael E. [mailto:MEHushagen at fedins.com]
> Sent: Tuesday, August 27, 2002 1:11 PM
> To: 'jdom-interest at jdom.org'
> Subject: [jdom-interest] Searching a JDOM document
> 
> 
> Here's a JDOM question for all the gurus out there:
> 
> I want to search a JDOM document and return the element that matches the
> name I pass in the parameters.  Here's what I have (it's recursive):
> 
> public Element findElement(Element current, String elementName)
> {
> 	if (current.getName() == elementName)
> 	{
> 		return current;
> 	}
> 	List children = current.getChildren();
> 	Iterator iterator = children.iterator();
> 	while (iterator.hasNext())
> 	{
> 		Element child = (Element) iterator.next();
> 		Element tempElement = findElement(child, elementName);
> 		if (tempElement != null)
> 			return tempElement;
> 	}
>              // Didn't find the element anywhere.
> 	return null;
> }
> 
> I call this method with the JDOM root element.  It works fine, but I was
> wondering if there is a more efficient or official way of doing this.
> 
> Thanks!
>  -Mike H.
> __________________________________________________________________
> This information is intended only for the use of the addressee(s) and may contain privileged, confidential or proprietary information.  If you are not the intended recipient, or the employee or agent responsible for delivering the message to the intended recipient, you are hereby notified that any dissemination, distribution, displaying, copying, or use of this information is strictly prohibited.  If you have received this communication in error, please notify us immediately at Administrator at fedins.com or by telephone at (800) 533-0472, and return the information to the sender with all copies deleted and destroyed.  Thank you.
> 
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com
> 
> 


-- 

Paul Chapman

Email:  chapman at zemsys.com
Mobile: +61 418 340 935




More information about the jdom-interest mailing list