I'd assume that modification of the List returned by the XPath query
does not modify the DOM tree. Try attribute.getParent().detach()
instead of iter.remove(). A better approach might be to select all the
img tags, use attributeValue to show the src attribute, and call
detach() on each.
--Evan
Ray Grieselhuber wrote:
Hello,
I'm trying to remove all of the images in an XHTML file. Here's what I
have:
XPath xpath = DocumentHelper.createXPath( "//img/@src");
xpath.setNamespaceURIs( map);
List nodes = xpath.selectNodes( root);
int listSize = nodes.size();
System.out.println("List: " + listSize);
Iterator iter = nodes.iterator();
while(iter.hasNext()){
Attribute attribute = (Attribute) iter.next();
String url = attribute.getValue();
System.out.println("Removing image: " + url);
iter.remove();
}
System.out.println(document.asXML());
When I output the document to XML, the image tags are still in there.
Am I missing a save or something?
Thanks!
Ray Grieselhuber
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job
easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache
Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
dom4j-user mailing list
dom4j-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dom4j-user
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
dom4j-user mailing list
dom4j-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dom4j-user