Xstream - order of attribute

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

Xstream - order of attribute

Márk Pásztor
Hello everybody,

I use xstream for a year. It's work very well.
But now I got a problem. I would like to write an xml file from an input xml file.
And I would like to preserve the order of input attributes to the output file.

Now looks like this:
INPUT:
<test a="w" b="I" c="553.0" d="1.0"/>
OUTPUT:
<test b="I" a="w" d="1.0" c="553.0"/>


Expected result:
INPUT:
<test a="w" b="I" c="553.0" d="1.0"/>
OUTPUT:
<test a="w" b="I" c="553.0" d="1.0"/>


What can I do in this case? Do you have any ideas?
Thank you!

--
Best regards,
Mark Pasztor
Reply | Threaded
Open this post in threaded view
|

Re: Xstream - order of attribute

Jörg Schaible-2
Hi Márk,

Márk Pásztor wrote:

> Hello everybody,
>
> I use xstream for a year. It's work very well.
> But now I got a problem. I would like to write an xml file from an input
> xml file.
> And I would like to preserve the order of input attributes to the output
> file.
>
> Now looks like this:
>
>
>
> *INPUT:<test a="w" b="I" c="553.0" d="1.0"/>OUTPUT:<test b="I" a="w"
> d="1.0" c="553.0"/>*
>
> Expected result:
>
>
>
> *INPUT:<test a="w" b="I" c="553.0" d="1.0"/>OUTPUT:<test a="w" b="I"
> c="553.0" d="1.0"/>*
>
> What can I do in this case? Do you have any ideas?

XStream writes attributes normally in declaration order of the Java type.

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: Xstream - order of attribute

Márk Pásztor
Hello,

Sorry i frogot to mension this problem is affect when I use converter.
When unmarshall method calling i try to get the attributes and i got this in bad order.
I use XppDomDriver because the default XppDriver doesn't work well with attributes (or i made something's wrong).
Sorry for my bad english.

for(int i = 0; i < reader.getAttributeCount(); i++){
    element.getAttributes().add(new Attribute(reader.getAttributeName(i), reader.getAttribute(i)));
}


Thanks for your help!



2014/1/21 Jörg Schaible <[hidden email]>
Hi Márk,

Márk Pásztor wrote:

> Hello everybody,
>
> I use xstream for a year. It's work very well.
> But now I got a problem. I would like to write an xml file from an input
> xml file.
> And I would like to preserve the order of input attributes to the output
> file.
>
> Now looks like this:
>
>
>
> *INPUT:<test a="w" b="I" c="553.0" d="1.0"/>OUTPUT:<test b="I" a="w"
> d="1.0" c="553.0"/>*
>
> Expected result:
>
>
>
> *INPUT:<test a="w" b="I" c="553.0" d="1.0"/>OUTPUT:<test a="w" b="I"
> c="553.0" d="1.0"/>*
>
> What can I do in this case? Do you have any ideas?

XStream writes attributes normally in declaration order of the Java type.

Cheers,
Jörg


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

    http://xircles.codehaus.org/manage_email





--
Üdvözlettel,
Pásztor Márk
Reply | Threaded
Open this post in threaded view
|

Re: Re: Xstream - order of attribute

Jörg Schaible-4
Hi Márk

Márk Pásztor wrote:

> Hello,
>
> Sorry i frogot to mension this problem is affect when I use converter.
> When unmarshall method calling i try to get the attributes and i got this
> in bad order.
> I use XppDomDriver because the default XppDriver doesn't work well with
> attributes (or i made something's wrong).
> Sorry for my bad english.
>
>
>
> *for(int i = 0; i < reader.getAttributeCount(); i++){
> element.getAttributes().add(new Attribute(reader.getAttributeName(i),
> reader.getAttribute(i)));}*
>
> Thanks for your help!

Sorry, but when I look at this code, I have the simple impression, that
there's a basic misunderstanding about what XStream does or how it works.

Looking at your XML, I'd expected something along:

=============== %< =============
 class Test { String a; String b; double c; double d };
 
 Test test = new Test;
 test.a = "w";
 test.b = "I";
 test.c = 553.0;
 test.d = 1.0;

 XStream xstream = new XStream();
 xstream.alias("test", Test.class);
 xstream.useAttributeFor(String.class);
 xstream.useAttributeFor(double.class);
 String xml = xstream.toXML(test);
 System.oout.println("OUTPUT:"+xml);
 Test copy = (Test)xstream.fromXML(xml);
=============== %< =============

What does your converter and why is it using an XppDom structure?

- Jörg

>
>
>
> 2014/1/21 Jörg Schaible <[hidden email]>
>
>> Hi Márk,
>>
>> Márk Pásztor wrote:
>>
>> > Hello everybody,
>> >
>> > I use xstream for a year. It's work very well.
>> > But now I got a problem. I would like to write an xml file from an
>> > input xml file.
>> > And I would like to preserve the order of input attributes to the
>> > output file.
>> >
>> > Now looks like this:
>> >
>> >
>> >
>> > *INPUT:<test a="w" b="I" c="553.0" d="1.0"/>OUTPUT:<test b="I" a="w"
>> > d="1.0" c="553.0"/>*
>> >
>> > Expected result:
>> >
>> >
>> >
>> > *INPUT:<test a="w" b="I" c="553.0" d="1.0"/>OUTPUT:<test a="w" b="I"
>> > c="553.0" d="1.0"/>*
>> >
>> > What can I do in this case? Do you have any ideas?
>>
>> XStream writes attributes normally in declaration order of the Java type.
>>
>> 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