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

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


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 exception");
    }
    
   
     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.
        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.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)

******************* 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20010604/664d7c48/attachment.htm


More information about the jdom-interest mailing list