XML Declaration

View: New views
6 Messages — Rating Filter:   Alert me  

XML Declaration

by Johannes Schneider-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi guys,

at the moment I am thinking about switchting from JDOM to woodstox and
staxmate:
The first tests look very promising.


But I have on small problem when writing the XML Declaration.

JDom creates that line:
<?xml version="1.0" encoding="UTF-8"?>

but Woodstock creates:
<?xml version='1.0' encoding='UTF-8'?>

Since I have many, many unit tests that contain that line I'd like to
reconfigure Woodstock to output the format I am used to.
Is there anything I can do about?

I debugged a bit and found that method:
com.ctc.wstx.sw.BufferingXmlWriter#writeXmlDeclaration

But that doesn't seem to be configurable....



Thanks,

Johannes

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



RE: XML Declaration

by Michael Kay :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>
> Since I have many, many unit tests that contain that line I'd
> like to reconfigure Woodstock to output the format I am used to.
> Is there anything I can do about?

Rewrite the unit tests. It's always a mistake to make tests depend on things
that aren't essential to correct functioning. When you're testing XML, you
should always canonicalize the XML before comparing with expected results:
otherwise, as you have found, your tests lock you into technology choices
and reduce the potential for change in the system.

It's a problem, as it happens, which is faced by a project I'm helping with
at the moment that has invested very heavily in creating a large battery of
test material.

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: XML Declaration

by Cowtowncoder :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, Oct 29, 2009 at 10:37 AM, Johannes Schneider
<mailings@...> wrote:

> Hi guys,
>
> at the moment I am thinking about switchting from JDOM to woodstox and
> staxmate:
> The first tests look very promising.
>
> But I have on small problem when writing the XML Declaration.
>
> JDom creates that line:
> <?xml version="1.0" encoding="UTF-8"?>
>
> but Woodstock creates:
> <?xml version='1.0' encoding='UTF-8'?>
>
> Since I have many, many unit tests that contain that line I'd like to
> reconfigure Woodstock to output the format I am used to.
> Is there anything I can do about?
>
> I debugged a bit and found that method:
> com.ctc.wstx.sw.BufferingXmlWriter#writeXmlDeclaration
>
> But that doesn't seem to be configurable....

There is nothing in API to really configure this, and like Michael
pointed out, this (type of quotes) is not something that tests should
assume is one way or the other. Same applies to attribute value
quoting, and amount of white space. I have had to fix quite a few unit
tests myself (for projects I have worked on) not to count on specific
formatting that is not defined by xml specification.

Still, if you absolutely do want to control this, your best bet is to
use method "writeRaw" on XMLStreamWriter2. All Woodstox
XMLStreamWriter implementations actually implement
org.codehaus.stax2.XMLStreamWriter2 (part of Stax2 extension API). It
will embed textual content as-is without any processing and can be
used to output what amounts to XML declaration. Also, you should not
call writeStartDocument (which would try to write declaration again).

-+ Tatu +-

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: XML Declaration

by Johannes Schneider-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

thanks for your fast replys. Of course you are right - I have to modify
my tests (will switch to XmlUnit).
But on the other side I think the type of quotes should really be
configurable.

Maybe one might discuss about the default settings (I know several XML
tools and nearly everyone uses " as quote) but at least it should be
configurable.


Sincerly,

Johannes

Tatu Saloranta wrote:

> On Thu, Oct 29, 2009 at 10:37 AM, Johannes Schneider
> <mailings@...> wrote:
>> Hi guys,
>>
>> at the moment I am thinking about switchting from JDOM to woodstox and
>> staxmate:
>> The first tests look very promising.
>>
>> But I have on small problem when writing the XML Declaration.
>>
>> JDom creates that line:
>> <?xml version="1.0" encoding="UTF-8"?>
>>
>> but Woodstock creates:
>> <?xml version='1.0' encoding='UTF-8'?>
>>
>> Since I have many, many unit tests that contain that line I'd like to
>> reconfigure Woodstock to output the format I am used to.
>> Is there anything I can do about?
>>
>> I debugged a bit and found that method:
>> com.ctc.wstx.sw.BufferingXmlWriter#writeXmlDeclaration
>>
>> But that doesn't seem to be configurable....
>
> There is nothing in API to really configure this, and like Michael
> pointed out, this (type of quotes) is not something that tests should
> assume is one way or the other. Same applies to attribute value
> quoting, and amount of white space. I have had to fix quite a few unit
> tests myself (for projects I have worked on) not to count on specific
> formatting that is not defined by xml specification.
>
> Still, if you absolutely do want to control this, your best bet is to
> use method "writeRaw" on XMLStreamWriter2. All Woodstox
> XMLStreamWriter implementations actually implement
> org.codehaus.stax2.XMLStreamWriter2 (part of Stax2 extension API). It
> will embed textual content as-is without any processing and can be
> used to output what amounts to XML declaration. Also, you should not
> call writeStartDocument (which would try to write declaration again).
>
> -+ Tatu +-
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



RE: XML Declaration

by Michael Kay :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> But on the other side I think the type of quotes should
> really be configurable.

Well, as a data point, in the W3C serialization spec we have options to
control quite a few aspects of serialization, and there has never been any
demand to add this. Recipients of the document shouldn't care. If you want
XML that can be compared byte-by-byte, serialize the output and then
canonicalize.

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: XML Declaration

by Johannes Schneider-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

As I have written I don't need this feature anymore for my unit tests. I
have switched to XmlUnit (and I think this has been a good decision).
And of course the produced xml is completely valid. This is just a minor
case of "might-be-nice-to-be-configurable".


Sincerly,

Johannes

Michael Kay wrote:

>> But on the other side I think the type of quotes should
>> really be configurable.
>
> Well, as a data point, in the W3C serialization spec we have options to
> control quite a few aspects of serialization, and there has never been any
> demand to add this. Recipients of the document shouldn't care. If you want
> XML that can be compared byte-by-byte, serialize the output and then
> canonicalize.
>
> Regards,
>
> Michael Kay
> http://www.saxonica.com/
> http://twitter.com/michaelhkay 
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email