cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Upayavira">
Subject Re: toSAX - Method for String
Date Fri, 18 Apr 2003 11:48:56 GMT
> I have written my first own generator;-) In the next step, I want to
> convert a given XML-String to SAX-Events without calling the methods
> startElement, endElement, aso.
> For example: Im generating a string like
> String xml = "<root>Any Text</root>";
> Now, im searching for a method, which converts this string
> automatically to SAX-Events, like foo.toSAX(xml);
> I've seen a method like this for a inputSource (File) but not for a
> string.

For 2.1, the below will do it. Don't know about 2.0.4.

import org.apache.avalon.excalibur.xml.Parser;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

            ByteArrayInputStream byteStream = new 
            InputSource inputSource = new InputSource(byteStream);
            Parser parser = (Parser) manager.lookup(Parser.ROLE);
            parser.parse(inputSource, xmlConsumer);

Read your string into a ByteArrayInputStream. Use that to build an inputSource. Have 
a parser generate SAX events from that inputStream.

Hope that helps.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message