Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XStream --> getting "id=someId"

 
Jorg Klein
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • 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
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • 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
 
Gerardo Tasistro
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic