From: Jacob K. <ho...@vi...> - 2010-09-02 21:50:49
|
Or, rather than at parse time, you can manipulate the DOM using a NodeFilter after the DOM has been created.... public class MyHrefFilter implements NodeFilter { public final short acceptNode(final Node n) { final String classVal = el.getAttribute("class"); if (classVal != null and classVal.indexOf("js-removal") > -1) { el.removeAttribute("href"); return NodeFilter.FILTER_ACCEPT; } else { return NodeFilter.FILTER_SKIP; } } } Then in your application code.... Document myDocument = .....; boolean expandEntityReferences = false; NodeIterator iter = ((DocumentTraversal) myDocument).createNodeIterator( myDocument, NodeFilter.SHOW_ELEMENT, new MyHrefFilter(), expandEntityReferences); //Must iterate in order to apply NodeFilter changes while (iter.nextNode() != null); iter.detach(); Jake On Wed, 1 Sep 2010 14:59:15 -0700 Andy Clark <an...@cy...> wrote: >For more advanced element processing, you'll probably want to implement your >own filter class. It's probably a good idea to use the element remover filter >as a starting point because when you want to remove an element you need to >remove all of its children (and their children) in addition to the starting >and ending element tags. > > There is more information about custom filters and how to use them in the >documentation. > > Sent from my iPad > > On Sep 1, 2010, at 3:58 AM, Clelio de Souza <cle...@gm...> wrote: > >> Hi all, >> >> I need to remove certain hyperlinks tags, which contain a certain "class" >>attribute, for instance: "<a href='http://link.com' class='js-removal'>link >>body</a>". The reason for it is that I want to keep all other hyperlinks >>("href") tags and only remove those marked by a certain attribute (I was >>wondering to use the "class" attribute for that). >> >> Is there anyway to do that? >> >> Note: The current "removeElement(String element)" method only remove the >>entire element. It does not consider any attributes information. >> >> Thanks & Regards, >> >> Clelio de Souza >> >> >> >> >> ------------------------------------------------------------------------------ >> This SF.net Dev2Dev email is sponsored by: >> >> Show off your parallel programming skills. >> Enter the Intel(R) Threading Challenge 2010. >> http://p.sf.net/sfu/intel-thread-sfd >> _______________________________________________ >> nekohtml-user mailing list >> nek...@li... >> https://lists.sourceforge.net/lists/listinfo/nekohtml-user |