Re: Newbie Problem with HasChildFilter

Derrick Oswald <[email protected]>
Newsgroups gmane.comp.parsers.htmlparser.user
Message-ID <[email protected]>
I think the TagNameFilter is case sensitive so it should be:
NodeFilter filter = new AndFilter(new TagNameFilter("BODY"),
               new HasChildFilter(new TagNameFilter("A"),true));

But, the filter you've constructed would find the BODY tag:
keep: tag named BODY and has a child named A

If you want the A tags insid the BODY tag it would be:
NodeFilter filter = new AndFilter(new TagNameFilter("A"),
               new HasParentFilter(new TagNameFilter("BODY"),true));


On Mon, Jul 6, 2009 at 10:33 AM, Roger Varley
<[email protected]>wrote:

> Hi
>
> I'm probably doing something stupid here, but I can't get the
> HasChildFilter to work properly. I am trying to get all the <a> tags
> that occur inside the <body> tag so I can re-write them. I don't want
> the javascript generated tags that occur inside the <head> tag. My
> test case is below.
>
> String testHtml = "<html><head><script><a href=JAVASCRIPT:openProc('\"
> + parent.contents.procUID[i] + \"','main')>"
>                             +"</script><body><table><tr><td>Cell
> Content</td></tr><tr><td>"
>                             +"<a target=\"main\"
> href=\"findXml.jsp?XMLFile=G455051\">Control
> Mechanism</a></td></tr></table></body></html>";
>
> Parser parser = new Parser(testHtml);
> NodeList originalPage = parser.parse(null);
> NodeFilter filter = new AndFilter(new TagNameFilter("body"),
>                new HasChildFilter(new TagNameFilter("a"),true));
> NodeList extract = originalPage.extractAllNodesThatMatch(filter, true);
>
> This fails to find any of the <a> tags - extract.size() is zero. Can
> someone point out
> what I'm doing wrong please.
>
> Regards
>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Htmlparser-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/htmlparser-user
>

------------------------------------------------------------------------------

_______________________________________________
Htmlparser-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/htmlparser-user
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.