Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] Serialize selected elements to a Writer.

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Wolfgang Hoschek <wolfgang.hoschek AT mac.com>
  • To: Wolfgang Hoschek <wolfgang.hoschek AT mac.com>
  • Cc: xom-interest AT lists.ibiblio.org
  • Subject: Re: [XOM-interest] Serialize selected elements to a Writer.
  • Date: Fri, 13 Oct 2006 14:41:00 -0700


On Oct 13, 2006, at 2:22 PM, Wolfgang Hoschek wrote:


On Oct 13, 2006, at 8:27 AM, David Bullock wrote:

Just reporting that my use-case, where I am using XOM as part of an
XML
templating scheme, isn't handled by Serializer. Not willing to
write my
own, I figured I'd just complain about it :-)

Specifically, it would have been useful if:

a) Serializer took a java.io.Writer in one of its constructors,
since this
is all that pageContext.getOut() can supply me with;

b) writeElement() [?] was public

I coped anyhow, using Node.toXML(), but I did begrudge the
StringBuffering
(or StringBuildering) that inevitably is incurred.

To be fair, when and if the memory footprint really starts to hurt,
I'll
probably go with StAX instead, but I found Node.query(String xpath)
compelling enough to stay with XOM for now (I guess that means that
actually
I would migrate to TrAX rather than StAX). I found it to be a nice
feature,
thanks.


XOM can stream output into StAX (or other serializers), also using a
public writeElement() method. See http://dsd.lbl.gov/nux/api/nux/xom/
io/StreamingSerializer.html

Wolfgang.

Furher, StaX can work with a java.io.Writer as well as an OutputStream, as in XMLOutputFactory.createXMLStreamWriter (java.io.Writer) and createXMLStreamWriter(java.io.OutputStrea, String encoding).

However, there's no standard way to detect the encoding used by a generic java.io.Writer or XMLStreamWriter. And StaX has no standard factory method for java.io.Writer that takes an encoding, such as createXMLStreamWriter(java.io.Writer, String encoding).

OutputStream remains a more reliable option than java.io.Writer. It also tends to be more efficient.

Wolfgang.






Archive powered by MHonArc 2.6.24.

Top of Page