Re: [Htmlparser-user] Retrieving html comments
Brought to you by:
derrickoswald
From: Derrick O. <der...@ro...> - 2007-07-11 00:30:14
|
Hi Cinza, There is no filter specifically for remark nodes, so you'll need to make your own. Start with an example like TagNameFilter.java and change the class name and the accept() method to return true for remarks. Something like this should work: public boolean accept (Node node) { return (node instanceof Remark); } Using that filter should give you all the comments in the page: NodeList remarks = parser.parse (new MyRemarkFilter()); Then the trouble begins. Remark nodes do not parse the content, so you will only be able to get at the entire contents with the getText() method. Then you either have to parse the text yourself for the 'attributes' or pervert the code that handles attribute parsing in the Lexer class to do the attribute parsing. One way to do that would be to enclose the text from the remark in a fake html tag and parse that. Something like this might work: parser = new Parser ("<html " + remark_text + " >"); Tag tag = parser.parse (null).element(0); Vector attributes = tag.getAttributesEx (); Derrick ----- Original Message ---- From: "c....@ar..." <c....@ar...> To: htm...@li... Sent: Tuesday, July 10, 2007 8:06:57 AM Subject: [Htmlparser-user] Retrieving html comments Hi, I'm new to this list so first of all... hello! Anyway, sorry for my english but it isn't my mother tongue. I have an html page but with no html, head nor body tag. I have only the code (that will be put in another page's body). In this page I have some html comments which I need to reach and to parse. For example: <!-- TEMPLATE TIPO 1 TABELLA id=28 version=8 --> I need to get all these comments and access to their attributes. Which kind of filter should I use? Or how can I do? Thank you! Cinzia ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ Htmlparser-user mailing list Htm...@li... https://lists.sourceforge.net/lists/listinfo/htmlparser-user |