Re: [Htmlparser-user] getting close. trying to replace one tag with another
Brought to you by:
derrickoswald
|
From: Derrick O. <der...@ro...> - 2007-11-21 23:21:54
|
The test (nl.extractAllNodesThatMatch(objFilter,false).size() > 0) appears to be redundant if you are going to recurse through all nodes anyway. If you get rid of that clause and it's else and instead recurse on the else of the (subnode instanceof ObjectTag) test, you should get all nodes.
----- Original Message ----
From: Randy Paries <rtp...@gm...>
To: htm...@li...
Sent: Wednesday, November 21, 2007 1:32:13 PM
Subject: [Htmlparser-user] getting close. trying to replace one tag with another
Hello
i am trying to replace a <object> tag with an <img> tag reading an
html file and sending the html to an editor.
It was working great unless the object tag was inside of a <div> or
nested inside some other tag.
So on the mailing list i found a recursive function example that i
have modified. It is working kindof.
As i am going thru the nodes if it is not an <object> tag and am just
adding that node.toHtml() to the StringBuffer Object that i am passing
to the editor.
if it is an object and a flash object i need to replace the object tag
with an image tag.
I am finding the object tag and replacing it ok, but as i traverse the
document, i am not adding everything to the StringBuffer Object. Like
tables in tables are not being added, and probably other tags within
tags.
if anyone can see something obvious that i am doing something wrong.
thanks
StringBuffer retStrBuf();
public void parse (Parser parser, NodeIterator i) throws
ParserException {
Node node;
Node subnode;
if( i == null ) {
i = parser.elements();
}
while( i.hasMoreNodes() ){
node = i.nextNode();
NodeList nl=null;
if(node != null) {
nl = node.getChildren();
if ( nl != null ){
if
(nl.extractAllNodesThatMatch(objFilter,false).size() > 0) {
NodeIterator x = nl.elements();
while ( x.hasMoreNodes() ){
subnode = x.nextNode();
if ( subnode instanceof ObjectTag){
ObjectTag ObjTag = (ObjectTag) subnode;
if ( ObjTag.getAttribute("classid") !=
null &&
ObjTag.getAttribute("classid").equals("clsid:d27cdb6e-ae6d-11cf-96b8-444553540000")
){
//remove of verbose stuff
ImageTag it = new ImageTag();
//remove of somemore verbose stuff
//System.out.println("--->"+it.toHtml());
retStrBuf.append(it.toHtml());
}
}else{
//System.out.println("--->"+subnode.toHtml());
retStrBuf.append(subnode.toHtml());
}
}
}else{
parse(parser,nl.elements());
}
}else{
//System.out.println(node.toHtml());
retStrBuf.append(node.toHtml());
}
}//end of null node
}//end of while
}//end of function
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Htmlparser-user mailing list
Htm...@li...
https://lists.sourceforge.net/lists/listinfo/htmlparser-user
|