Hello,
I have a html file
I parse the html, then i want to update some info between the tags, then write out everything back to a file.
Is this possible??
thanks
Randy
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Recent additions (the last couple of integration builds) have added methods to collect all top level nodes into a NodeList, and then print lists out with toHtml(). So if you use visitors or filters:
NodeList list = parser.parse (null); // no filter gets everything
list.visitAllNodesWith (visitor); // process nodes here
// or NodeList subset = list.extractAllNodesThatMatch (filter);
// ... process the subset here (they're still in list)
System.out.println (list.toHtml ());
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I must be missing something
if i do the following the page gets outputed
Parser parser = new Parser("C:\\UnitNet\\UnitNetServlet\\webapp\\paries\\mainUgly.html");
NodeList nl = parser.parse(null);
System.out.println( nl.toHtml() );
but then if i try( factory stuff deleted but tags we added ), unWelcomeList comes back with a size of zero.....
NodeList unWelcomeList = nl.extractAllNodesThatMatch (
new OrFilter ( new NodeClassFilter (UnitNetWelcomeTag.class),
new NodeClassFilter (UnitNetUpdateTag.class)
)
);
but, if i leave out the NodeList nl = parser.parse(null); and change nl.extractAllNodesThatMatch
to parser.extractAllNodesThatMatch i get the stuff expected. Boy i hope this makes sense.
Randy
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Maybe this will help...
When are you registering your custom tags?
You need to register these before parsing, either with parser.parse() or parser.extractAllNodesThatMatch.
The custom nodes are only formed when the page is parsed.
After the nodes are in a NodeList it's too late.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I have a html file
I parse the html, then i want to update some info between the tags, then write out everything back to a file.
Is this possible??
thanks
Randy
Basically yes.
Recent additions (the last couple of integration builds) have added methods to collect all top level nodes into a NodeList, and then print lists out with toHtml(). So if you use visitors or filters:
NodeList list = parser.parse (null); // no filter gets everything
list.visitAllNodesWith (visitor); // process nodes here
// or NodeList subset = list.extractAllNodesThatMatch (filter);
// ... process the subset here (they're still in list)
System.out.println (list.toHtml ());
Hello,
I must be missing something
if i do the following the page gets outputed
Parser parser = new Parser("C:\\UnitNet\\UnitNetServlet\\webapp\\paries\\mainUgly.html");
NodeList nl = parser.parse(null);
System.out.println( nl.toHtml() );
but then if i try( factory stuff deleted but tags we added ), unWelcomeList comes back with a size of zero.....
NodeList unWelcomeList = nl.extractAllNodesThatMatch (
new OrFilter ( new NodeClassFilter (UnitNetWelcomeTag.class),
new NodeClassFilter (UnitNetUpdateTag.class)
)
);
but, if i leave out the NodeList nl = parser.parse(null); and change nl.extractAllNodesThatMatch
to parser.extractAllNodesThatMatch i get the stuff expected. Boy i hope this makes sense.
Randy
No, it doesn't make a lot of sense. Sorry.
Maybe this will help...
When are you registering your custom tags?
You need to register these before parsing, either with parser.parse() or parser.extractAllNodesThatMatch.
The custom nodes are only formed when the page is parsed.
After the nodes are in a NodeList it's too late.