//HTMLDocument.
String text =
"<html>" + "<head>" + "<title>My own HTML file</title>" + "</head>" + "<body>"
+ "<h2>This is a test exercise for me!</h2>" + "</body>" + "</html>";
HTMLDocument document = HTMLParser.createDocument(text);
assertNotNull(document);
String pathStr = "html.head.title";
NodePath path = NodePathParser.toPath(pathStr);
assertNotNull(path);
assertEquals(path.toString(), "HTML[0].HEAD[0].TITLE[0]");
System.out.println("PATH: " + path.toString());
HTMLNode node = NodePathUtil.lookFor(document.getRoot(), path);
assertNotNull(node);
assertEquals(node.getName(), Name.TITLE);
//Add a Tag to HTMLDocument.
NodeImpl impl = new NodeImpl("h2 id = \"dds\"".toCharArray(), Name.H2);
node.addChild(impl);
assertNotNull(node.getChildrenNode().get(1));
assertEquals(node.getChildren().get(1).getName(), Name.H2);
System.out.println("THE NEW NODE-NAME: " + node.getChildrenNode().get(1).getName().toString());
System.out.println("THE NEW NODE-VALUE: " + new String(node.getChildren().get(1).getValue()));
//Add a Table to HTMLDocument.
HTMLDocument doc = HTMLParser.createDocument("<table border='1'><tr></tr></table>");
HTMLNode table = NodePathUtil.lookFor(doc.getRoot(), NodePathParser.toPath("html.body.table"));
node.addChild(table);
//Remove a Node which is text in format from HTMLDocument.
System.out.println("\n\nRemove:");
HTMLNode contentNode = NodePathUtil.lookFor(document.getRoot(), NodePathParser.toPath("html.head.title.content"));