(in this example doc is the Document for the DOM tree)
        
      public void print(Writer out,String encoding) {
                XMLSerializer xser = new XMLSerializer();
                xser.asDOMSerializer();
                xser.setOutputCharStream(out);
                OutputFormat of = new OutputFormat(doc,encoding,true);
                xser.setOutputFormat(of);
                try {
                        xser.serialize(doc);
                }
                catch (IOException e) {
                        e.printStackTrace();
                }
        }

-----Original Message-----
From: Scott Sanders [mailto:[EMAIL PROTECTED]
Sent: Thursday, February 17, 2000 9:22 AM
To: [EMAIL PROTECTED]
Subject: Re: [Java|1.0.1] Parsing from StringBuffer...


Do you have a quick example?

> I've done it by using the serializer classes and serializing to a
> java.io.StringWriter.
>
> - Greg
>
> Is there something like that to do the opposite, ie, given a DOM tree, how
> do I get it into a single String or StringBuffer.
>
> > create a java.io.StringReader, then create a org.xml.sax.InputSource
from
> > the StringReader.  Pass the input source into the parse() method and you
> are
> > home free.
>
> >> I have some data in a StringBuffer. These data are XML. I'd like to
parse
> >> them. How can I "feed" the DOM parser wo/ writing a file ?

Reply via email to