<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META content="MSHTML 5.00.3211.1700" name=GENERATOR></HEAD>
<BODY>
<DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=941065716-04062001><SPAN
class=412310117-04062001>Kris,</SPAN></SPAN></FONT></DIV>
<DIV><SPAN class=941065716-04062001></SPAN> </DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=941065716-04062001>To
create a Document from a String, do something like this:</SPAN></FONT></DIV>
<DIV><SPAN class=941065716-04062001></SPAN><FONT color=#0000ff face=Arial
size=2> </FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN
class=941065716-04062001> SAXBuilder builder = new
SAXBuilder(); <BR> <BR> try
{<BR> Document doc = builder.build(new
StringReader(xmlString));<BR> }catch(JDOMException je)
{}</SPAN></FONT></DIV>
<DIV><SPAN class=941065716-04062001></SPAN><FONT color=#0000ff face=Arial
size=2> </FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=941065716-04062001>Note
that a StringReader is used.</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=941065716-04062001>Sonya
Pettit</SPAN></FONT></DIV></DIV>
<BLOCKQUOTE>
<DIV align=left class=OutlookMessageHeader dir=ltr><FONT face=Tahoma
size=2>-----Original Message-----<BR><B>From:</B> krishna muthyala
[mailto:muthyalakris@yahoo.com]<BR><B>Sent:</B> Monday, June 04, 2001 12:11
PM<BR><B>To:</B> jdom-interest@jdom.org<BR><B>Subject:</B> [jdom-interest]
help please GURUS.. !!!<BR><BR></DIV></FONT>
<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></BODY></HTML>