Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

XStream --> getting "id=someId"

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everybody,

I am working on a program that generates XML files.
Its the first time that I build something like this and thats why I tried to do this with XStream. XStream is really nice and easy if you just want to generate XML files from Java POJO's.

Its going ok and for example if made this one:


I want to have an Id in the header now, and I want to give that id myself like:


Anybody know how I can do this?
I can't find it on the internet..

THx
 
Marshal
Posts: 26915
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see the word "attribute" anywhere in XStream's FAQ. Or in any of the XStream pages I skimmed during the last 90 seconds. But if it can be done, you would have to do some special configuration to tell XStream to produce an attribute instead of a child element. Which leads me to believe it can't be done.

I see XStream has a mailing list. It's likely to have a higher density of XStream experts than the Ranch does.
 
Jorg Klein
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also tought that this could not be done with XStream..
Does anybody know what I should use instead of XStream.
I want it to be as simple as possible (thats why I picked XStream in the first place)

Greetings
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I have this sort of problem I just do println to an OutputStream or Writer - simple to write and debug and doesn't require that much more typing.
If you have an object that represents the data in a "Person", give that object a writeXML( OutputStream ) method. Then all you have to do is write the root Element start, have all the Persons write themselves and write the root close.
Bill
 
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jorg check out Castor. It is much bigger jar than XStream and that is why I don't use it much, but it has more flexibility since it uses a mapping file and you can configure stuff like you need it.

http://www.castor.org/

Namely look here

http://www.castor.org/xml-mapping.html#3.-The-Mapping-File
[ March 24, 2006: Message edited by: Gerardo Tasistro ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic