Question about Using XStream

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

Question about Using XStream

郝强_BYR
Hi,
    I use xstream to read and write xml file in my project, and I encounter a problem. In the project, there's an xml configuration file, but it is used by two  programs.  The other program may add some unknown tags which are the tags of xml file that don't have the corresponding class defined in my java program, but they are useful in the other program. The aim is to reserve these strange tags when the classes are wrote back to xml file. It means the strange tags should be wrote back, though I don't need them in my program. I have learnt your tutorials online and many blogs. Now I can discard these unknown tags, so there will not be any exceptions when the xstream encounter unknown tags, but when it is wrote back, these tags don't appear in the xml file any more.
   I want to ask whether there is a method that it can reserve these unknow tags (the tags of xml file that don't have the corresponding class defined in my java program) in the xml file after my java program read the file and write back.

   Thanks. Waiting for your reply.

Best regards!
miccio
 
Reply | Threaded
Open this post in threaded view
|

Re: Question about Using XStream

Jörg Schaible-4
Hi Miccio,

郝强_BYR wrote:

> Hi,
>     I use xstream to read and write xml file in my project, and I
>     encounter a problem. In the project, there's an xml configuration
>     file, but it is used by two  programs.  The other program may add some
>     unknown tags which are the tags of xml file that don't have the
>     corresponding class defined in my java program, but they are useful in
>     the other program. The aim is to reserve‍ these strange tags when the
>     classes are wrote back to xml file. It means the strange tags should
>     be wrote back, though I don't need them in my program. I have learnt
>     your tutorials online and many blogs. Now I can discard these unknown
>     tags, so there will not be any exceptions when the xstream encounter
>     unknown tags, but when it is wrote back, these tags don't appear in
>     the xml file any more.‍
>    I want to ask whether there is a method that it can reserve these
>    unknow tags (the tags of xml file that don't have the corresponding
>    class defined in my java program‍) in the xml file after my java
>    program read the file and write back.
>
>
>    Thanks. Waiting for your reply.
>
>
> Best regards!
> miccio

There's no support for this in XStream. XStream is "from Java to XML and
back" and therefore not designed to keep unknown elements, because they are
not part of the Java model. Either you enhance your model or you may have a
look at XSTR-474. Peter Knego once developed an enhancement with a similar
functionality with certain limitations.

Cheers,
Jörg



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

    http://xircles.codehaus.org/manage_email