Stuart Rossiter wrote:
> On 6 April 2013 21:21, Jörg Schaible
> <[email protected]> wrote:
>
>> Hi Stuart,
>>
>> Stuart Rossiter wrote:
>>
>> > Hi. With the latest XStream 1.4.4 (on Windows with Java 6), using the
>> StAX
>> > driver instead of the XPP3 or JAXP DOM one means that toXML includes
>> > the XML declaration (<?xml version="1.0"?>) *and* doesn't pretty-print
>> > the string. The other drivers work fine.
>> >
>> > This looks like a consistency bug, given that the declaration should
>> never
>> > be written, and it should always be pretty-printed. However, the JIRA
>> > log-in link doesn't allow me to request a userid as the XStream pages
>> > suggest. (It says 'contact your JIRA admin'.)
>> >
>> > So:
>> > (a) Is this a bug? (Browsing JIRA suggests none registered.)
>>
>> No. Actually we normally have only XML parsers, but StAX is the one of
>> the view XML frameworks that also includes a writer. And XStream is using
>> the defaults of the framework. Note, that the default for all the other
>> parsers (PrettyPrintWriter of XStream) does not support namespaces.
>>
>>
> That makes sense, but surely XStream should present a consistent API that
> isn't dependent on the driver used?
>
> The XStream toXML method Javadoc states that it "Serialize[s] an object to
> a pretty-printed XML String".
>
> The FAQ states:
> Q. Why does XStream not write an XML declaration?
> A. XStream is designed to write XML snippets, so you can embed its output
> into an existing stream or string. You can write the XML declaration
> yourself into the Writer before using it to call XStream.toXML(writer).
>
> So, if the wrapped driver doesn't do this by default, shouldn't XStream be
> doing it (either by configuring the driver internally or parsing its
> outputs)? Particularly since XStream has no functionality to pretty-print
> or remove the header 'manually'. (I appreciate that there are probably
> XML-related libraries that can do this for me, but still...)
>
> Am I missing something here?
That's the point: XStream does *not* write the XML header. However, in case
of StAX it is written by javax.xml.stream.XMLStreamWriter. XStream is
limited to its capabilities. Iy you have no need for namespaces, you can use
XStream's PrettyPrintWriter instead.
- Jörg
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email