Fwd: [jdom-interest] help please GURUS.. !!!

krishna muthyala muthyalakris at yahoo.com
Mon Jun 4 09:36:10 PDT 2001


 Its me again 
Just tried something else and got this error 
org.jdom.JDOMException: Error on line 1: The root element is required in a well-formed document.
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:407)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:499)
        at com.sone.util.XMLResourceTagParser.parseXml(XMLResourceTagParser.java:89)
        at com.sone.util.XMLResourceTagParser.getResourceTag(XMLResourceTagParser.java:64)
        at com.sone.servlets.CommandServlet.service(CommandServlet.java:101)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
        at org.apache.tomcat.core.Handler.service(Handler.java:286)
        at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
        at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)
        at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
        at org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection(Ajp12ConnectionHandler.java:166)
        at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
        at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
        at java.lang.Thread.run(Thread.java:484)
Root cause: org.xml.sax.SAXParseException: The root element is required in a well-formed document.
        at org.apache.xerces.framework.XMLParser.reportError(XMLParser.java:1008)
        at org.apache.xerces.framework.XMLDocumentScanner.reportFatalXMLError(XMLDocumentScanner.java:625)
        at org.apache.xerces.framework.XMLDocumentScanner$XMLDeclDispatcher.endOfInput(XMLDocumentScanner.java:841)
        at org.apache.xerces.framework.XMLDocumentScanner.endOfInput(XMLDocumentScanner.java:417)
        at org.apache.xerces.validators.common.XMLValidator.sendEndOfInputNotifications(XMLValidator.java:565)
        at org.apache.xerces.readers.DefaultEntityHandler.changeReaders(DefaultEntityHandler.java:1026)
        at org.apache.xerces.readers.XMLEntityReader.changeReaders(XMLEntityReader.java:168)
        at org.apache.xerces.readers.AbstractCharReader.changeReaders(AbstractCharReader.java:150)
        at org.apache.xerces.readers.AbstractCharReader.lookingAtChar(AbstractCharReader.java:217)
        at org.apache.xerces.framework.XMLDocumentScanner$XMLDeclDispatcher.dispatch(XMLDocumentScanner.java:741)
        at org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:380)
        at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:900)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:395)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:499)
        at com.sone.util.XMLResourceTagParser.parseXml(XMLResourceTagParser.java:89)
        at com.sone.util.XMLResourceTagParser.getResourceTag(XMLResourceTagParser.java:64)
        at com.sone.servlets.CommandServlet.service(CommandServlet.java:101)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
        at org.apache.tomcat.core.Handler.service(Handler.java:286)
        at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
        at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)
        at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
        at org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection(Ajp12ConnectionHandler.java:166)
        at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
        at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
        at java.lang.Thread.run(Thread.java:484)

 

this is what I did

doc = sax.build(new StringReader(XmlStream)); 

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..

Thanks

Krishna

  krishna muthyala <muthyalakris at yahoo.com> wrote: From krishna muthyala Mon Jun 4 09:10:34 2001
X-Apparently-To: muthyalakris at yahoo.com via web13405.mail.yahoo.com; 04 Jun 2001 09:25:52 -0700 (PDT)
Return-Path: 
Received: from dorothy.denveronline.net (206.168.141.2)
by mta309.mail.yahoo.com with SMTP; 04 Jun 2001 09:25:51 -0700 (PDT)
Received: from dorothy.denveronline.net (localhost [127.0.0.1])
by dorothy.denveronline.net (8.9.3/8.9.3) with ESMTP id KAA14774;
Mon, 4 Jun 2001 10:22:32 -0600 (MDT)
Received: from web13409.mail.yahoo.com (web13409.mail.yahoo.com [216.136.172.17])
by dorothy.denveronline.net (8.9.3/8.9.3) with SMTP id KAA13149
for ; Mon, 4 Jun 2001 10:10:39 -0600 (MDT)
Message-ID: <20010604161034.79621.qmail at web13409.mail.yahoo.com>
Received: from [139.131.241.10] by web13409.mail.yahoo.com; Mon, 04 Jun 2001 09:10:34 PDT
From: krishna muthyala 
To: jdom-interest at jdom.org
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="0-1804289383-991671034=:79619"
Subject: [jdom-interest] help please GURUS.. !!!
Sender: jdom-interest-admin at jdom.org
Errors-To: jdom-interest-admin at jdom.org
X-BeenThere: jdom-interest at jdom.org
X-Mailman-Version: 2.0.1
Precedence: bulk
List-Help: 
List-Post: 
List-Subscribe: ,

List-Id: JDOM Mailing List for General Issues and Updates 
List-Unsubscribe: ,

List-Archive: 
Date: Mon, 4 Jun 2001 09:10:34 -0700 (PDT)
Content-Length: 17648


Hi

I request some help, the following is the task

I have an application which spits out xml as a string
something like this

"xml=<?xml version="1.0" encoding="UTF-8"?>
<session>
  <!--Session Element -->
  <resource>Session</resource>
  <useridElement>kris</useridElement>
  <passwordElement>kris</passwordElement>
  </session>"

the code for writing xml is as follows

public static String createDocument() 
    {
    String xmlString="";
    
        // Create the root element
        Element sessionElement = new Element("session");
        //create the document
        
        Document myDocument = new Document (sessionElement);
            
        
        //add a comment
        sessionElement.addContent(new Comment("Session Element "));

        //add some child elements
        /*
         * Note that this is the first approach to adding an element and
         * textual content.  The second approach is commented out.
         */
        Element resource = new Element("resource");
        resource.addContent("session");
        sessionElement.addContent(resource);
        
        //add some more elements
        sessionElement.addContent(new Element("useridElement").addContent("kris"));
        sessionElement.addContent(new Element("! passwordElement").addContent("kris"));
        

          //print the document

        try 
        {
            XMLOutputter outputter = new XMLOutputter("  ", true);
            outputter.output(myDocument, System.out);
            System.out.println("XMLOUtputter created");
            //xmlString=outputter.outputString(myDocument);
        } 
        catch (java.io.IOException e) 
        {
            e.printStackTrace();
        }
        
        ! ;                
        //return myDocument;
        return xmlString;
    }

 

***************end method *******************


This string is posted to a servlet, which then does a 

String value = request.getParameter("xml"); 
MyParser myparser = new MyParser();
resource = myparser.parseXML(value);

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.

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? 

I tried something like this in my parsing class

public String parseXml(String XmlStream)
  {
  String resource="";
  Document doc;
   try
   {
     System.out.println("inside parseXML");
   
     SAXBuilder sax = new SAXBuilder();
     doc = sax.build(XmlStream);
     Element root = doc.getRootElement();
     
     Element r = root.getChild(resource);
     String re = r.toString();
     resource = re;
     }
     catch(JDOMException e) 
     {
            e.printStackTrace();
     }
   catch (Exception e)
   {
   e.printStackTrace();
   System.out.println("parsing exceptio! n");
    }
    
   
     return resource;
  }

 

and this throws  the following exception

********** error *******************

org.jdom.JDOMException: Error on line 0: File "" not found.
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:407)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:533)
        at com.sone.util.XMLResourceTagParser.parseXml(XMLResourceTagParser.java:87)
        at com.sone.util.XMLResourceTagParser.getResourceTag(XMLResourceTagParser.java:64)
        at com.sone.servlets.CommandServlet.service(CommandServlet.java:101)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
        at org.apache.tomcat.core.Handler! .service(Handler.java:286)
        at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
        at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)
        at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
        at org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection(Ajp12ConnectionHandler.java:166)
        at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
        at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
        at java.lang.Thread.run(Thread.java:484)
Root cause: org.xml.sax.SAXParseException: File "" not found.
     &nbs! p;  at org.apache.xerces.framework.XMLParser.reportError(XMLParser.java:1014)
        at org.apache.xerces.readers.DefaultEntityHandler.startReadingFromDocument(DefaultEntityHandler.java:499)
        at org.apache.xerces.framework.XMLParser.parseSomeSetup(XMLParser.java:304)
        at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:899)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:395)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:533)
        at com.sone.util.XMLResourceTagParser.parseXml(XMLResourceTagParser.java:87)
        at com.sone.util.XMLResourceTagParser.getResourceTag(XMLResourceTagParser.java:64)
        at com.sone.servlet! s.CommandServlet.service(CommandServlet.java:101)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
        at org.apache.tomcat.core.Handler.service(Handler.java:286)
        at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
        at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)
        at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
        at org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection(Ajp12ConnectionHandler.java:166)
        at org.apache.tomcat.service.T! cpWorkerThread.runIt(PoolTcpEndpoint.java:416)
        at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
        at java.lang.Thread.run(Thread.java:484)

******************* end error****************************

can any of the gurus help me overcome this problem, this is very important for me right now...

Thanks

Appreciate your time and response

kris

 

 

 

 

 


 



 

concern for a cleaner world, for a better tomorrow 

         http://www.greenpeace.org



---------------------------------
Do You Yahoo!?
Yahoo! Mail Personal Address - Get email at your own domain with Yahoo! Mail.


 

concern for a cleaner world, for a better tomorrow 

         http://www.greenpeace.org



---------------------------------
Do You Yahoo!?
Yahoo! Mail Personal Address - Get email at your own domain with Yahoo! Mail.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20010604/45a8c4f3/attachment.htm


More information about the jdom-interest mailing list