Thank you Daniel - This is great stuff!
Cheers
tim
-----Original Message-----
From: A mailing list for discussion about Sun Microsystem's Java Servlet
API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of VoiD
Sent: 28 March 2001 11:40
To: [EMAIL PROTECTED]
Subject: Re: XML,Servlet, Parser Prob
Here is some code, that i use, that may be of use to you...
import javax.xml.parsers.*;
import org.w3c.dom.*;
private Document d;
private String xmlString = "<Hello><World>!</World></Hello>";
try
{
DocumentBuilderFactory docBuilderFactory =
DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
ByteArrayInputStream is = new ByteArrayInputStream(xml.getBytes());
d = docBuilder.parse(is);
}
catch(Exception e)
{
e.printStackTrace(System.err);
}
NodeList nl = d.getChildNodes();
...
Then i think you know the rest. Hope this is what you wanted...
/Daniel
-----Original Message-----
From: A mailing list for discussion about Sun Microsystem's Java Servlet
API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of Tim
Wynne
Sent: den 28 mars 2001 11:15
To: [EMAIL PROTECTED]
Subject: [SERVLET-INTEREST] XML,Servlet, Parser Prob
Hi,
I have a servlet that uses COS send a post to another servlet. I've
included a parameter called "XMLMSG" which contains a string, which is valid
XML. The servlet at the other end can pick out the XML with
String xmlrequest = req.getParameter("XMLMSG");
This all works fine. However, I want to Parse this XML message, preferably
using a SAX Parser - but the parameters to the Parse function are either a
org.xml.sax.InputSource or a java.lang.String (identifying the systemid). I
want to actually parse the String xmlrequest itself.
I can see only one solution so far - have the listening servlet write the
string to a filesystem temp file, then provide the known URI to this temp
file as a String. However - this doesn't seem particuarly elegant, and will
probably impact the performance, as there will definately be a write to the
disk.
Can anybody think of a better solution, i.e. a parser that allows me to
parse a string? I have a feeling that there could be a simple answer to this
(such is life).
My apologies if this is slightly offtopic, but I've posted to the
xml-interest sun list, and recieved only a reply saying tha the list is
currently "held". This has obviously not helped :-)
Regards,
Tim
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html