Re: [Htmlparser-user] For Help
Brought to you by:
derrickoswald
From: Derrick O. <Der...@Ro...> - 2006-05-22 12:26:37
|
I would subclass StringFilter or RegexFilter and override it's accept method to something like: public boolean accept (Node node) { String string; boolean ret; ret = false; if (node instanceof Remark) { string = ((Remark)node).getText (); if (!getCaseSensitive ()) string = string.toUpperCase (getLocale ()); ret = (-1 != string.indexOf (mUpperPattern)); } return (ret); } Then you could get the two remarks (your example indicates they have the same text) with: NodeList list = parser.extractAllNodesThatMatch (new RemarkFilter ("-- this is a comment --"); From the two Remark nodes returned you should be able to navigate to the text between them with something like: Remark first = (Remark)(list.elementAt (0)); NodeList siblings = remark.getParent ().getChildren (); for (int i = 0; i < siblings.length (); i++) if (siblings.elementAt (i) == first) mytext = siblings.elementAt (i + 1).toHtml (); Jiang Zhiguo wrote: > Hi,ALL > if I want to get the content in comment tag; > like this: > <!-- this is a comment --> > * aaaaaaaaa* > <!-- this is a comment --> > I want to get the *"aaaaaaaaa"* > how to do it? > thanks! |