XStream assistance

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

XStream assistance

Fawkes711
Greetings.

I am attempting to change a java object back into it's xml string but I am having some difficulty with getting what I want.

I have attempted xs.toXML with the appropriate XmlFriendlyReplacer, to ensure I do not get a double underscore some of my field names, however this method gives me newlines in the string, which I do not want.

I then moved on to xs.marshal using a StringWriter, this solved my newlines problem, but I get my double underscores.

Anyone know a solution to either method so I get neither doubleunderscores and newlines?

Thanks in advance!
Reply | Threaded
Open this post in threaded view
|

Re: XStream assistance

Paul Hammant-3
The object goes from XML into a Java object just fine?  But its the conversion back to XML that's the only problem?

how about this hack :

   xml = xs.toXML(..).replace("__","_");

- Paul

On Wed, Sep 7, 2011 at 2:23 PM, Fawkes711 <[hidden email]> wrote:

Greetings.

I am attempting to change a java object back into it's xml string but I am
having some difficulty with getting what I want.

I have attempted xs.toXML with the appropriate XmlFriendlyReplacer, to
ensure I do not get a double underscore some of my field names, however this
method gives me newlines in the string, which I do not want.

I then moved on to xs.marshal using a StringWriter, this solved my newlines
problem, but I get my double underscores.

Anyone know a solution to either method so I get neither doubleunderscores
and newlines?

Thanks in advance!
--
View this message in context: http://old.nabble.com/XStream-assistance-tp32418743p32418743.html
Sent from the xstream - user mailing list archive at Nabble.com.


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

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: XStream assistance

Fawkes711
I don't necessarily want to manipulate the string manually like that.

Paul Hammant-3 wrote
The object goes from XML into a Java object just fine?  But its the
conversion back to XML that's the only problem?

how about this hack :

   xml = xs.toXML(..).replace("__","_");

- Paul

On Wed, Sep 7, 2011 at 2:23 PM, Fawkes711 <ocfung@gmail.com> wrote:

>
> Greetings.
>
> I am attempting to change a java object back into it's xml string but I am
> having some difficulty with getting what I want.
>
> I have attempted xs.toXML with the appropriate XmlFriendlyReplacer, to
> ensure I do not get a double underscore some of my field names, however
> this
> method gives me newlines in the string, which I do not want.
>
> I then moved on to xs.marshal using a StringWriter, this solved my newlines
> problem, but I get my double underscores.
>
> Anyone know a solution to either method so I get neither doubleunderscores
> and newlines?
>
> Thanks in advance!
> --
> View this message in context:
> http://old.nabble.com/XStream-assistance-tp32418743p32418743.html
> Sent from the xstream - user mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: XStream assistance

Jörg Schaible-3
In reply to this post by Fawkes711
Hi,

Fawkes711 wrote:

>
> Greetings.
>
> I am attempting to change a java object back into it's xml string but I am
> having some difficulty with getting what I want.
>
> I have attempted xs.toXML with the appropriate XmlFriendlyReplacer, to
> ensure I do not get a double underscore some of my field names, however
> this method gives me newlines in the string, which I do not want.
>
> I then moved on to xs.marshal using a StringWriter, this solved my
> newlines problem, but I get my double underscores.
>
> Anyone know a solution to either method so I get neither doubleunderscores
> and newlines?

Your're using XStream version 1.3.x or 1.4.x?

The XmlFriendlyReplacer (1.3.x) or NameCoder (1.4.x) is used by the
H(ierachrical)S(tream)Reader or HSWriter generated by the HSDriver that
passes the name coding instance to the new reader/writer. So these two code
snippets are equivalent:

============ %< ===========
XStream xstream = new XStream(new XppDriver(new NoNameCoder()));
Object result = xstream.fromXML(xmlString);
============ %< ===========

and

============ %< ===========
HierarchicalStreamDriver driver = new XppDriver(new NoNameCoder())
XStream xstream = new XStream((HierarchicalStreamDriver)null);
Object result = xstream.unmarshal(
  driver.createReader(new StringReader(xmlString)));
============ %< ===========

In the second case the XStream instance is not involved creating the
HSReader that is already initialized with the proper name coding.

Hope this helps,
Jörg


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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: XStream assistance

Fawkes711
Hi,

I am using 1.3.x. I am still unable to determine how to proceed using xstream to convert my object back into an xml string with no double underscores and no newlines.

Regards,

Orson
Reply | Threaded
Open this post in threaded view
|

Re: XStream assistance

Jörg Schaible-2
Fawkes711 wrote:

>
> Hi,
>
> I am using 1.3.x. I am still unable to determine how to proceed using
> xstream to convert my object back into an xml string with no double
> underscores and no newlines.

xstream.unmarshal(New CompactWriter(new XmlFriendlyReplacer(...,...)));

- Jörg


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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: XStream assistance

Ishfaq Ahmad
This post has NOT been accepted by the mailing list yet.
In reply to this post by Paul Hammant-3
I followed the same to replace the double underscore with single one and it worked fine for me.


Thanks -Paul