xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Scott Boag/CAM/Lotus" <Scott_B...@lotus.com>
Subject RE: Problem with org.apache.xalan.xpath.xml.TreeWalker
Date Wed, 26 Jan 2000 16:05:12 GMT

Brian Dupras <briand@centera.com> wrote:
> Is there an existing example using the Serializer class?

import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.Serializer;

...

  public static String nodeToString(Node node) throws SAXException,
IOException
  {
    StringWriter sw = new StringWriter();
    OutputFormat of = new OutputFormat("xml", "UTF8", false);

    Serializer serializer = Serializer.makeSerializer(sw, of);
    if(node.getNodeType() == Node.DOCUMENT_NODE)
      serializer.serialize((Document)node);
    else if(node.getNodeType() == Node.ELEMENT_NODE)
      serializer.serialize((Element)node);
    else
      System.out.println("Can only serialize documents and elements!");
    return sw.toString();
  }

I think you can also pass in null for the OutputFormat, if you don't want
that much control.

-scott






Mime
View raw message