[jdom-interest] XPath and JDOM
    Malachi de AElfweald 
    malachi at tremerechantry.com
       
    Tue Nov 19 19:50:14 PST 2002
    
    
  
Perhaps something like this?
public static Element getSpecificChild(Element parentNode, String elemName, 
String attrName, String attrVal)
{
	List children = parentNode.getChildren(elemName);
	if( (children == null) || (children.size() == 0) )
		return null;
	Iterator iter = children.iterator();
	while(iter.hasNext())
	{
		Element elem = (Element)iter.next();
		String value = elem.getAttributeValue(attrName);
		if( (value != null) && value.equals(attrValue) )
			return elem;
	}
	return null;
}
then, just call something like:
	Element correctChild = getSpecificChild(someNode, "entry", "id", "5");
Mal
On Mon, 18 Nov 2002 16:12:49 +0200, Stefanos Kaklamanis <stefka at gnt.gr> wrote:
> Hi,
>
> I want to get a specific element ( where attribute id =5 ) from an JDOM 
> document and edit/remove it from the document.
>
> Any suggestion about solutions and tools?
>
> Thanks,
> Stefan
>
> PS. I already have a look at Jaxen and SAXPath, but I could take what i 
> want.
>
-- 
    
    
More information about the jdom-interest
mailing list