|
Listing all tags in a HTML document |
|
import be.arci.html.*;
import java.io.File;
/**List all tags in HTML documents */
public class HTMLScannerExample3
{
public static void main(String[] args)
{//we do not specify any tag name, but will request to return them all
//the tag ID (HTMLTag.iID) will be asTagNames.length (== 1) for all tags
//element [0] == null: not interested in text content
String[] asTagNames = new String[] { null};
for (int i = 0; i < args.length; i++)
{
try {
//replace with "new HTMLScanner(new URL(args[i]));" for networked documents
HTMLScanner hs = new HTMLScanner(new File(args[i]));
HTMLTag[] tags = hs.getTags(asTagNames, false);//false: also return unnamed tags
for (int j = 0; j < tags.length; j++)
System.out.println(tags[j]);
} catch (Exception e) { e.printStackTrace(); } //URL exceptions or IO exceptions
}
}
}