xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dane Foster" <dfos...@equitytg.com>
Subject Re: SAX parser should parse xml-document thats a string value ..?
Date Tue, 24 Oct 2000 20:12:15 GMT
You have a few options available to you.

1) You can wrap you an String in an InputSource object by creating a
StringReader object passing your String along as it's constructor argument,
then passing the StringReader to the InputSource object. i.e

InputSource iSource = new InputSource( new StringReader( myString ) );
//parser configuration details has been skipped for simplicity
parser.parse( iSource );

You could also use a CharArrayReader or ByteArrayInputStream as arguments to
the InputSource's constructor.

2) You can skip the InputSource object and convert your String to a an array
of bytes and pass that as an argument to a ByteArrayInputStream, then pass
the ByteArrayInputStream as a parameter to the parser's parse() method. See
documentation for exact signature of parse()

Peace

Dane
----- Original Message -----
From: "Peter Oliver Monz" <peo@ftk.de>
To: <general@xml.apache.org>
Sent: Tuesday, October 24, 2000 11:11 AM
Subject: SAX parser should parse xml-document thats a string value ..?


> Hello!
>
> I hope anybody can help me. I used the xalan-Sample PureSAX
> for testing. The sample uses files for input of xml- and xsl-files.
> But I am looking for a method to read the xml/xsl-data directly
> from a String or StringBuffer e.g. like:
>
>
> SAXParser saxparser = new SAXParser();
>
> String xmldata = "<?xml version=\"1.0\"?><CATALOG><BOOK><TITLE>A
Certain
> Justice</TITLE><AUTHOR>P.D.
>
James</AUTHOR><YEAR-PUBLISHED>1998</YEAR-PUBLISHED><ISBN>0375401091</ISBN></
BOOK></CATALOG>";
>
> saxparser.parse(xmldata);
>
>
> But thats does not run, because of parse want to open the file named
> "<?xml version ... " and the file is not existend.
>
> Now I am looking for method that allows me to read the data direct
> from a stringvalue.
>
> Can anybody help me?
>
>
> thanx.
>
> peter monz


----------------------------------------------------------------------------
----


> ---------------------------------------------------------------------
> In case of troubles, e-mail:     webmaster@xml.apache.org
> To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
> For additional commands, e-mail: general-help@xml.apache.org


Mime
View raw message