<P> Its me again
<P>Just tried something else and got this error
<P><STRONG>org.jdom.JDOMException: Error on line 1: The root element is required in a well-formed document.<BR> at org.jdom.input.SAXBuilder.build(SAXBuilder.java:407)<BR> at org.jdom.input.SAXBuilder.build(SAXBuilder.java:499)<BR> at com.sone.util.XMLResourceTagParser.parseXml(XMLResourceTagParser.java:89)<BR> at com.sone.util.XMLResourceTagParser.getResourceTag(XMLResourceTagParser.java:64)<BR> at com.sone.servlets.CommandServlet.service(CommandServlet.java:101)<BR> at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)<BR> at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)<BR> at org.apache.tomcat.core.Handler.service(Handler.java:286)<BR> at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)<BR> at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)<BR> at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)<BR> at org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection(Ajp12ConnectionHandler.java:166)<BR> at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)<BR> at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)<BR> at java.lang.Thread.run(Thread.java:484)<BR>Root cause: org.xml.sax.SAXParseException: The root element is required in a well-formed document.<BR> at org.apache.xerces.framework.XMLParser.reportError(XMLParser.java:1008)<BR> at org.apache.xerces.framework.XMLDocumentScanner.reportFatalXMLError(XMLDocumentScanner.java:625)<BR> at org.apache.xerces.framework.XMLDocumentScanner$XMLDeclDispatcher.endOfInput(XMLDocumentScanner.java:841)<BR> at org.apache.xerces.framework.XMLDocumentScanner.endOfInput(XMLDocumentScanner.java:417)<BR> at org.apache.xerces.validators.common.XMLValidator.sendEndOfInputNotifications(XMLValidator.java:565)<BR> at org.apache.xerces.readers.DefaultEntityHandler.changeReaders(DefaultEntityHandler.java:1026)<BR> at org.apache.xerces.readers.XMLEntityReader.changeReaders(XMLEntityReader.java:168)<BR> at org.apache.xerces.readers.AbstractCharReader.changeReaders(AbstractCharReader.java:150)<BR> at org.apache.xerces.readers.AbstractCharReader.lookingAtChar(AbstractCharReader.java:217)<BR> at org.apache.xerces.framework.XMLDocumentScanner$XMLDeclDispatcher.dispatch(XMLDocumentScanner.java:741)<BR> at org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:380)<BR> at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:900)<BR> at org.jdom.input.SAXBuilder.build(SAXBuilder.java:395)<BR> at org.jdom.input.SAXBuilder.build(SAXBuilder.java:499)<BR> at com.sone.util.XMLResourceTagParser.parseXml(XMLResourceTagParser.java:89)<BR> at com.sone.util.XMLResourceTagParser.getResourceTag(XMLResourceTagParser.java:64)<BR> at com.sone.servlets.CommandServlet.service(CommandServlet.java:101)<BR> at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)<BR> at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)<BR> at org.apache.tomcat.core.Handler.service(Handler.java:286)<BR> at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)<BR> at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)<BR> at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)<BR> at org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection(Ajp12ConnectionHandler.java:166)<BR> at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)<BR> at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)<BR> at java.lang.Thread.run(Thread.java:484)</STRONG></P>
<P> </P>
<P>this is what I did</P>
<P>doc = sax.build(new StringReader(XmlStream)); </P>
<P>as suggested in FAQ and by some gurus here... so what changes do I need to make in my createDocument(), to make it a well formed document with a root etc..</P>
<P>Thanks</P>
<P>Krishna</P>
<P> <B><I>krishna muthyala <muthyalakris@yahoo.com></I></B> wrote:
<BLOCKQUOTE style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid">From krishna muthyala Mon Jun 4 09:10:34 2001<BR>X-Apparently-To: muthyalakris@yahoo.com via web13405.mail.yahoo.com; 04 Jun 2001 09:25:52 -0700 (PDT)<BR>Return-Path: <JDOM-INTEREST-ADMIN@JDOM.ORG><BR>Received: from dorothy.denveronline.net (206.168.141.2)<BR>by mta309.mail.yahoo.com with SMTP; 04 Jun 2001 09:25:51 -0700 (PDT)<BR>Received: from dorothy.denveronline.net (localhost [127.0.0.1])<BR>by dorothy.denveronline.net (8.9.3/8.9.3) with ESMTP id KAA14774;<BR>Mon, 4 Jun 2001 10:22:32 -0600 (MDT)<BR>Received: from web13409.mail.yahoo.com (web13409.mail.yahoo.com [216.136.172.17])<BR>by dorothy.denveronline.net (8.9.3/8.9.3) with SMTP id KAA13149<BR>for <JDOM-INTEREST@JDOM.ORG>; Mon, 4 Jun 2001 10:10:39 -0600 (MDT)<BR>Message-ID: <20010604161034.79621.qmail@web13409.mail.yahoo.com><BR>Received: from [139.131.241.10] by web13409.mail.yahoo.com; Mon, 04 Jun 2001 09:10:34 PDT<BR>From: krishna muthyala <MUTHYALAKRIS@YAHOO.COM><BR>To: jdom-interest@jdom.org<BR>MIME-Version: 1.0<BR>Content-Type: multipart/alternative; boundary="0-1804289383-991671034=:79619"<BR>Subject: [jdom-interest] help please GURUS.. !!!<BR>Sender: jdom-interest-admin@jdom.org<BR>Errors-To: jdom-interest-admin@jdom.org<BR>X-BeenThere: jdom-interest@jdom.org<BR>X-Mailman-Version: 2.0.1<BR>Precedence: bulk<BR>List-Help: <MAILTO:JDOM-INTEREST-REQUEST@JDOM.ORG?SUBJECT=HELP><BR>List-Post: <MAILTO:JDOM-INTEREST@JDOM.ORG><BR>List-Subscribe: <HTTP: lists.denveronline.net mailman listinfo jdom-interest>,<BR><MAILTO:JDOM-INTEREST-REQUEST@JDOM.ORG?SUBJECT=SUBSCRIBE><BR>List-Id: JDOM Mailing List for General Issues and Updates <JDOM-INTEREST.JDOM.ORG><BR>List-Unsubscribe: <HTTP: lists.denveronline.net mailman listinfo jdom-interest>,<BR><MAILTO:JDOM-INTEREST-REQUEST@JDOM.ORG?SUBJECT=UNSUBSCRIBE><BR>List-Archive: <HTTP: lists.denveronline.net jdom-interest lists /><BR>Date: Mon, 4 Jun 2001 09:10:34 -0700 (PDT)<BR>Content-Length: 17648<BR><BR>
<P>Hi</P>
<P>I request some help, the following is the task</P>
<P>I have an application which spits out xml as a string<BR>something like this</P>
<P>"xml=<?xml version="1.0" encoding="UTF-8"?><BR><session><BR> <!--Session Element --><BR> <resource>Session</resource><BR> <useridElement>kris</useridElement><BR> <passwordElement>kris</passwordElement><BR> </session>"</P>
<P>the code for writing xml is as follows</P>
<P><STRONG>public static String createDocument() <BR> {<BR> String xmlString="";<BR> <BR> // Create the root element<BR> Element sessionElement = new Element("session");<BR> //create the document<BR> <BR> Document myDocument = new Document (sessionElement);<BR> <BR> <BR> //add a comment<BR> sessionElement.addContent(new Comment("Session Element "));</STRONG></P>
<P><STRONG> //add some child elements<BR> /*<BR> * Note that this is the first approach to adding an element and<BR> * textual content. The second approach is commented out.<BR> */<BR> Element resource = new Element("resource");<BR> resource.addContent("session");<BR> sessionElement.addContent(resource);<BR> <BR> //add some more elements<BR> sessionElement.addContent(new Element("useridElement").addContent("kris"));<BR> sessionElement.addContent(new Element("! passwordElement").addContent("kris"));<BR> </STRONG></P>
<P><STRONG> //print the document</STRONG></P>
<P><STRONG> try <BR> {<BR> XMLOutputter outputter = new XMLOutputter(" ", true);<BR> outputter.output(myDocument, System.out);<BR> System.out.println("XMLOUtputter created");<BR> //xmlString=outputter.outputString(myDocument);<BR> } <BR> catch (java.io.IOException e) <BR> {<BR> e.printStackTrace();<BR> }<BR> <BR> ! ; <BR> //return myDocument;<BR> return xmlString;<BR> }</STRONG></P>
<P><STRONG></STRONG> </P>
<P>***************end method *******************</P>
<P><BR>This string is posted to a servlet, which then does a </P>
<P><STRONG>String value = request.getParameter("xml"); <BR>MyParser myparser = new MyParser();<BR>resource = myparser.parseXML(value);</STRONG></P>
<P>and gets the whole xml string. I want to pass this string to a class that uses the JDOM API and extract the value for resource tag and do some processing.</P>
<P>My question is how is it done? , also is there a better way to set the identifier in the request object from the application for the servlet to get it out of the request object? </P>
<P>I tried something like this in my parsing class</P>
<P><STRONG>public String parseXml(String XmlStream)<BR> {<BR> String resource="";<BR> Document doc;<BR> try<BR> {<BR> System.out.println("inside parseXML");<BR> <BR> SAXBuilder sax = new SAXBuilder();<BR> doc = sax.build(XmlStream);<BR> Element root = doc.getRootElement();<BR> <BR> Element r = root.getChild(resource);<BR> String re = r.toString();<BR> resource = re;<BR> }<BR> catch(JDOMException e) <BR> {<BR> e.printStackTrace();<BR> }<BR> catch (Exception e)<BR> {<BR> e.printStackTrace();<BR> System.out.println("parsing exceptio! n");<BR> }<BR> <BR> <BR> return resource;<BR> }</STRONG></P>
<P><STRONG></STRONG> </P>
<P>and this throws the following exception</P>
<P><FONT color=purple>********** error *******************</FONT></P>
<P><FONT color=#800080></FONT><FONT color=purple>org.jdom.JDOMException: Error on line 0: File "" not found.<BR> at org.jdom.input.SAXBuilder.build(SAXBuilder.java:407)<BR> at org.jdom.input.SAXBuilder.build(SAXBuilder.java:533)<BR> at com.sone.util.XMLResourceTagParser.parseXml(XMLResourceTagParser.java:87)<BR> at com.sone.util.XMLResourceTagParser.getResourceTag(XMLResourceTagParser.java:64)<BR> at com.sone.servlets.CommandServlet.service(CommandServlet.java:101)<BR> at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)<BR> at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)<BR> at org.apache.tomcat.core.Handler! .service(Handler.java:286)<BR> at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)<BR> at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)<BR> at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)<BR> at org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection(Ajp12ConnectionHandler.java:166)<BR> at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)<BR> at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)<BR> at java.lang.Thread.run(Thread.java:484)<BR>Root cause: org.xml.sax.SAXParseException: File "" not found.<BR> &nbs! p; at org.apache.xerces.framework.XMLParser.reportError(XMLParser.java:1014)<BR> at org.apache.xerces.readers.DefaultEntityHandler.startReadingFromDocument(DefaultEntityHandler.java:499)<BR> at org.apache.xerces.framework.XMLParser.parseSomeSetup(XMLParser.java:304)<BR> at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:899)<BR> at org.jdom.input.SAXBuilder.build(SAXBuilder.java:395)<BR> at org.jdom.input.SAXBuilder.build(SAXBuilder.java:533)<BR> at com.sone.util.XMLResourceTagParser.parseXml(XMLResourceTagParser.java:87)<BR> at com.sone.util.XMLResourceTagParser.getResourceTag(XMLResourceTagParser.java:64)<BR> at com.sone.servlet! s.CommandServlet.service(CommandServlet.java:101)<BR> at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)<BR> at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)<BR> at org.apache.tomcat.core.Handler.service(Handler.java:286)<BR> at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)<BR> at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)<BR> at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)<BR> at org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection(Ajp12ConnectionHandler.java:166)<BR> at org.apache.tomcat.service.T! cpWorkerThread.runIt(PoolTcpEndpoint.java:416)<BR> at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)<BR> at java.lang.Thread.run(Thread.java:484)</FONT></P>
<P>******************* end error****************************</P>
<P>can any of the gurus help me overcome this problem, this is very important for me right now...</P>
<P>Thanks</P>
<P>Appreciate your time and response</P>
<P>kris</P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P><BR> </P><BR><BR>
<P> </P>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<P>concern for a cleaner world, for a better tomorrow </P>
<P> <A href="http://www.greenpeace.org/">http://www.greenpeace.org</A></P></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE>
<P><BR>
<HR SIZE=1>
<B>Do You Yahoo!?</B><BR><A href="http://personal.mail.yahoo.com/?.refer=mailiyfoot">Yahoo! Mail Personal Address</A> - Get email at your own domain with Yahoo! Mail.</BLOCKQUOTE></MAILTO:JDOM-INTEREST-REQUEST@JDOM.ORG?SUBJECT=UNSUBSCRIBE></MAILTO:JDOM-INTEREST-REQUEST@JDOM.ORG?SUBJECT=SUBSCRIBE></MAILTO:JDOM-INTEREST@JDOM.ORG></MAILTO:JDOM-INTEREST-REQUEST@JDOM.ORG?SUBJECT=HELP><BR><BR><P> </P>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<P>concern for a cleaner world, for a better tomorrow </P>
<P> <A href="http://www.greenpeace.org">http://www.greenpeace.org</A></P></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE><p><br><hr size=1><b>Do You Yahoo!?</b><br>
<a href="http://personal.mail.yahoo.com/?.refer=mailiyfoot">Yahoo! Mail Personal Address</a> -
Get email at your own domain with Yahoo! Mail.