B
bigbinc
For reasons, I need to create an html document through org.w3c.dom, I
can get the tags and classnames and the values but I still cant
generate an html page. Basically I am doing what jsp does through the
dom interface. This is my code thus far and the libraries I am using.
import org.w3c.dom.html.*;
import org.apache.html.dom.*;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.NodeList;
public void printDOMPage(PrintWriter _out, String spaces, Node node) {
_out.println(spaces + "<br>Name:" + node.getNodeName());
_out.println(spaces + "<br>Value:" + node.getNodeValue());
_out.println(spaces + "<br>Type:" + node.getNodeType());
_out.println(spaces + "<br>#Children:" +
node.getChildNodes().getLength());
_out.println(spaces + node.getClass().getName());
if (node.getAttributes() != null && node.getAttributes().getLength()
_out.println(spaces + "Attributes:");
NamedNodeMap myMap = node.getAttributes();
for (int i = 0; i < myMap.getLength(); i++) {
Node myAttribute = myMap.item(i);
_out.println(spaces + " Name:" +
myAttribute.getNodeName());
_out.println(spaces + " Value:" +
myAttribute.getNodeValue());
} // end of the for
} // end of the if
_out.println("-----------------------------------------------------------");
spaces += " ";
NodeList myChildren = node.getChildNodes();
for(int i = 0; i < myChildren.getLength(); i++) {
printDOMPage(_out, spaces, myChildren.item(i));
} // end of the for
} // end of the functino
can get the tags and classnames and the values but I still cant
generate an html page. Basically I am doing what jsp does through the
dom interface. This is my code thus far and the libraries I am using.
import org.w3c.dom.html.*;
import org.apache.html.dom.*;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.NodeList;
public void printDOMPage(PrintWriter _out, String spaces, Node node) {
_out.println(spaces + "<br>Name:" + node.getNodeName());
_out.println(spaces + "<br>Value:" + node.getNodeValue());
_out.println(spaces + "<br>Type:" + node.getNodeType());
_out.println(spaces + "<br>#Children:" +
node.getChildNodes().getLength());
_out.println(spaces + node.getClass().getName());
if (node.getAttributes() != null && node.getAttributes().getLength()
{
_out.println(spaces + "Attributes:");
NamedNodeMap myMap = node.getAttributes();
for (int i = 0; i < myMap.getLength(); i++) {
Node myAttribute = myMap.item(i);
_out.println(spaces + " Name:" +
myAttribute.getNodeName());
_out.println(spaces + " Value:" +
myAttribute.getNodeValue());
} // end of the for
} // end of the if
_out.println("-----------------------------------------------------------");
spaces += " ";
NodeList myChildren = node.getChildNodes();
for(int i = 0; i < myChildren.getLength(); i++) {
printDOMPage(_out, spaces, myChildren.item(i));
} // end of the for
} // end of the functino