preserving the spaces after deserialization

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

preserving the spaces after deserialization

Nicolas HERNANDEZ
Dear all,

I would like to preserve the spaces after deserialization.

I read that the substitution of newlines, tabs characters with spaces
is part of the XML specification [1].
I would prefer not to use xml entities as it is suggested.

I also read that the XML recommendation offers a way to keep these
characters by using the special attribute xml:space="preserve".
Unfortunately it seems that no available parser accept it.
Is there one ? Any other idea by using converters may be ? Do I have to
implement my own parser ?

Any suggestion will be welcome.

/Nicolas

[1] http://xstream.codehaus.org/faq.html#XML_attribute_normalization

[2] http://www.w3.org/TR/xml/#sec-white-space


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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: preserving the spaces after deserialization

Jörg Schaible-4
Hi Nicolas,

Nicolas HERNANDEZ wrote:

> Dear all,
>
> I would like to preserve the spaces after deserialization.
>
> I read that the substitution of newlines, tabs characters with spaces
> is part of the XML specification [1].
> I would prefer not to use xml entities as it is suggested.
>
> I also read that the XML recommendation offers a way to keep these
> characters by using the special attribute xml:space="preserve".
> Unfortunately it seems that no available parser accept it.
> Is there one ? Any other idea by using converters may be ? Do I have to
> implement my own parser ?
>
> Any suggestion will be welcome.

Sorry, but I don't understand, what you are really up-to. White spaces in
XML values *are* preserved, because they are part of an objects value. Apart
from that you get an object (graph) as result and there's no equivalent for
white spaces between Java objects ... ?!?

Cheers,
- Jörg



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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: preserving the spaces after deserialization

Nicolas HERNANDEZ
Hi Jörg,

The spaces are preserved when I serialize using toXML method. When I check
with an editor I see the original indentation.

But when I use the following method xstream.fromXML(myXMLString) to
deserialize,
all the newlines and tabs characters are replaced by simple whitespaces
characters.

Is it more clear ?



> Hi Nicolas,
>
> Nicolas HERNANDEZ wrote:
>
>> Dear all,
>>
>> I would like to preserve the spaces after deserialization.
>>
>> I read that the substitution of newlines, tabs characters with spaces
>> is part of the XML specification [1].
>> I would prefer not to use xml entities as it is suggested.
>>
>> I also read that the XML recommendation offers a way to keep these
>> characters by using the special attribute xml:space="preserve".
>> Unfortunately it seems that no available parser accept it.
>> Is there one ? Any other idea by using converters may be ? Do I have to
>> implement my own parser ?
>>
>> Any suggestion will be welcome.
>
> Sorry, but I don't understand, what you are really up-to. White spaces in
> XML values *are* preserved, because they are part of an objects value.
> Apart
> from that you get an object (graph) as result and there's no equivalent
> for
> white spaces between Java objects ... ?!?
>
> Cheers,
> - Jörg
>
>
>
> ---------------------------------------------------------------------
> 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


Reply | Threaded
Open this post in threaded view
|

Re: Re: preserving the spaces after deserialization

Jörg Schaible-4
Hi Nicolas,

Nicolas HERNANDEZ wrote:

> Hi Jörg,
>
> The spaces are preserved when I serialize using toXML method. When I check
> with an editor I see the original indentation.
>
> But when I use the following method xstream.fromXML(myXMLString) to
> deserialize,
> all the newlines and tabs characters are replaced by simple whitespaces
> characters.
>
> Is it more clear ?

No.

============ %< ==============
 XStream xstream = new XStream();
 String orig = "  abc\n def\n\t\t";
 String xml = xstream.toXML(orig);
 System.out.println(xml);
 if(orig.equals(xstream.fromXML(xml)))
   System.out.println("XML is equal!");
============ %< ==============

The code above will print

============ %< ==============
<string>  abc
 def
                </string>
XML is equal!
============ %< ==============

The string has been marshalled into XML and unmarshalled again and its still
equal.

Cheers,
- Jörg



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

    http://xircles.codehaus.org/manage_email