Hi

yes, kinda offtopic, but here's an answer.....

I use xerces and came up with the following:

if you look at the InputSource constructors you will see that you can
pass it a StringReader... and a StringReader has a constructor that you
can pass a String....

<snip>
String theXML;
theXML = httpservletrequest.getParameter("xml");
if (theXML == null) {
         // houston, we have a problem
} else{
        // do stuff with the xml
        try {
            XMLReader xr = XMLReaderFactory.createXMLReader();
            MyHandler  handler = new MyHandler();
            xr.setContentHandler(handler);
            xr.setErrorHandler(handler);
            StringReader sr = new StringReader(theXML);
            xr.parse(new InputSource(sr));
        }
        }catch (SAXException se){
          //dostuff

        }catch (IOException ioe){
           //do stuff
        }
}

<snip>

Ms Andrea Foster

Analyst Programmer
Unibase Development
tel : 021 414 4715
fax : 021 418 1288
cell : 082 516 0277

>>> [EMAIL PROTECTED] 03/28/01 11:14AM >>>
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

Reply via email to