KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > DisplayAllElements


1 import au.id.jericho.lib.html.*;
2 import java.util.*;
3 import java.io.*;
4 import java.net.*;
5
6 public class DisplayAllElements {
7     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
8         String JavaDoc sourceUrlString="data/test.html";
9         if (args.length==0)
10           System.err.println("Using default argument of \""+sourceUrlString+'"');
11         else
12             sourceUrlString=args[0];
13         if (sourceUrlString.indexOf(':')==-1) sourceUrlString="file:"+sourceUrlString;
14         PHPTagTypes.register();
15         PHPTagTypes.PHP_SHORT.deregister(); // remove PHP short tags for this example otherwise they override processing instructions
16
MasonTagTypes.register();
17         Source source=new Source(new URL(sourceUrlString));
18         source.setLogWriter(new OutputStreamWriter(System.err)); // send log messages to stderr
19
source.fullSequentialParse();
20         List elementList=source.findAllElements();
21         for (Iterator i=elementList.iterator(); i.hasNext();) {
22             Element element=(Element)i.next();
23             System.out.println("-------------------------------------------------------------------------------");
24             System.out.println(element.getDebugInfo());
25             if (element.getAttributes()!=null) System.out.println("XHTML StartTag:\n"+element.getStartTag().tidy(true));
26             System.out.println("Source text with content:\n"+element);
27         }
28         System.out.println(source.getCacheDebugInfo());
29   }
30 }
31
Popular Tags