SAX with JAXP

A

Araxes Tharsis

Hi,

I want to parse a XML document with SAX (using JAXP) and found lot's of
examples of parsing from a file. But... I have the XML in a String variable
and want to parse from there. All the 'parse' methods from the SAXParse
class receive a File, or a InputStream, or a URI... I don't want to create a
file just to be able to parse the XML (for performance reasons).
Any help appreciated,

Araxes Tharsis
 
A

Araxes Tharsis

Just 2 groups is crossposting? Ok... I will stop publishing to these 2
groups at the same time.
Best Regards,
Araxes Tharsis
 
M

Murat G.

Araxes Tharsis said:
Hi,

I want to parse a XML document with SAX (using JAXP) and found lot's of
examples of parsing from a file. But... I have the XML in a String variable
and want to parse from there. All the 'parse' methods from the SAXParse
class receive a File, or a InputStream, or a URI... I don't want to create a
file just to be able to parse the XML (for performance reasons).
Any help appreciated,

Araxes Tharsis

Use org.xml.Parser.parse(org.xml.sax.InputSource....) method.

-murat
 
S

Sudsy

Araxes said:
Hi,

I want to parse a XML document with SAX (using JAXP) and found lot's of
examples of parsing from a file. But... I have the XML in a String variable
and want to parse from there. All the 'parse' methods from the SAXParse
class receive a File, or a InputStream, or a URI... I don't want to create a
file just to be able to parse the XML (for performance reasons).
Any help appreciated,

Araxes Tharsis

Since this came up recently, it's apparent that you didn't check
the archives. If you dig through the javadocs (another good place
to start) then you'll find that InputSource is also accepted as
an argument to SAXParser#parse(). Further, InputSource has a
constructor which takes a Reader as the argument. Further digging
uncovers the StringReader class which extends Reader. So if you've
got a String named s, parsing is as basic as:
SAXParser.parse( new InputSource( new StringReader( s ) ),
DefaultHandler );
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top