DOM-ache
ammar510 Sep 19, 2005 5:58 AMhello, please help me (SOS)
i build the underling servlet and deploy it on jboss / jbossweb-tomcat50.sar but the output was as follow
ref>>>org.apache.xerces.jaxp.DocumentBuilderFactoryImpl@c68059 ref>>>org.apache.xerces.jaxp.DocumentBuilderImpl@145582 ref>>>[#document: null] doc>>>[root: null]
then i copy the code and execute it in a class in the main(String args[]) the output was
ref>>>org.apache.crimson.jaxp.DocumentBuilderFactoryImpl@26e431 ref>>>org.apache.crimson.jaxp.DocumentBuilderImpl@19134f4 ref>>>org.apache.crimson.tree.XmlDocument@42719c doc>>> <root><attribute><name>speed</name><value>2.0 hz</value></attribute><attribute><name>provider</name><value>intel</value></attribute></root>
i will loose my mind, what is the problem, how could this happened, there is nothing worng please please please please please please please please please please please please help me
package test; import java.io.IOException; import java.io.StringReader; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import javax.servlet.http.*; public class DomServlet extends HttpServlet { public void doGet(HttpServletRequest request,HttpServletResponse response) { response.setContentType("text/html"); getXmlData(); } public void getXmlData() { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); System.out.println("ref>>>"+factory); DocumentBuilder builder = builder = factory.newDocumentBuilder(); System.out.println("ref>>>"+builder); Document doc = builder.parse(new InputSource(new StringReader(getStoredXML()))); System.out.println("ref>>>"+doc); Element root =doc.getDocumentElement(); System.out.println("doc>>>"+root); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch(ParserConfigurationException ex) { ex.printStackTrace(); } } public static String getStoredXML() { String declaration = ""; return "<?xml version=\"1.0\"?>"+ "<root>"+ "<attribute>"+ "<name>speed</name>"+ "<value>2.0 hz</value>"+ "</attribute>"+ "<attribute>"+ "<name>provider</name>"+ "<value>intel</value>"+ "</attribute>"+ "</root>"; } }