Help: how to acheive the extensibility using Xstream

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

Help: how to acheive the extensibility using Xstream

Miao Liqiang

Hi, I need help .
 
How can ii acheive the same effcts with articals below using Xstream.
I followed the  tutorail in the XStream web-site, but there are run-time exceptions
Can anyone help me?
 
Regards,
 
Miao Liqiang
 
 
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 

XML Elements are Extensible

XML documents can be extended to carry more information.

Look at the following XML NOTE example:

<note>
<to>Tove</to>
<from>Jani</from>
<body>Don't forget me this weekend!</body>
</note>

Let's imagine that we created an application that extracted the <to>, <from>, and <body> elements from the XML document to produce this output:

MESSAGE

To: Tove
From: Jani

Don't forget me this weekend!

Imagine that the author of the XML document added some extra information to it:

<note>
<date>2002-08-01</date>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

Should the application break or crash?

No. The application should still be able to find the <to>, <from>, and <body> elements in the XML document and produce the same output.

XML documents are Extensible.


 

Reply | Threaded
Open this post in threaded view
|

RE: Help: how to acheive the extensibility using Xstream

Jörg Schaible
Hi Miao,

Xstream is by default a simple serializer i.e. you give it an object and it will create XML out of it and is able to convert this XML back into your object. This means that XStream by default will unmarshal exactly the expected elements of the structure - not less, but also not more. Main reason is, that not initializing members leaves an object in an undetermined state.

Said that, you can write your own converter for a class though - in your example for 'node'. You have to read all children out of the XML stream and set the appropriate fields.

There are some open issues, that address this problem though:
http://jira.codehaus.org/browse/XSTR-68
http://jira.codehaus.org/browse/XSTR-210

- Jörg


________________________________

        From: Miao Liqiang [mailto:[hidden email]]
        Sent: Tuesday, January 17, 2006 9:44 AM
        To: [hidden email]
        Subject: [xstream-user] Help: how to acheive the extensibility using Xstream
       
       
        Hi, I need help .
         
        How can ii acheive the same effcts with articals below using Xstream.
        I followed the  tutorail in the XStream web-site, but there are run-time exceptions
        Can anyone help me?
       
        Regards,
         
        Miao Liqiang
         
         
        ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
         
       
        XML Elements are Extensible


        XML documents can be extended to carry more information.

        Look at the following XML NOTE example:

                <note>
        <to>Tove</to>
        <from>Jani</from>
        <body>Don't forget me this weekend!</body>
        </note>
               

        Let's imagine that we created an application that extracted the <to>, <from>, and <body> elements from the XML document to produce this output:

        MESSAGE

        To: Tove
        From: Jani

        Don't forget me this weekend!

               

        Imagine that the author of the XML document added some extra information to it:

                <note>
        <date>2002-08-01</date>
        <to>Tove</to>
        <from>Jani</from>
        <heading>Reminder</heading>
        <body>Don't forget me this weekend!</body>
        </note>
               

        Should the application break or crash?

        No. The application should still be able to find the <to>, <from>, and <body> elements in the XML document and produce the same output.

        XML documents are Extensible.