Two Laptop Bag
The moose likes XML and Related Technologies and the fly likes XStream --> getting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XStream --> getting "id=someId"" Watch "XStream --> getting "id=someId"" New topic

XStream --> getting "id=someId"

Jorg Klein
Ranch Hand

Joined: Feb 13, 2006
Posts: 33
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..

Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

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

Joined: Feb 13, 2006
Posts: 33
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)

William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13035
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.
Gerardo Tasistro
Ranch Hand

Joined: Feb 08, 2005
Posts: 362
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.

Namely look here
[ March 24, 2006: Message edited by: Gerardo Tasistro ]
I agree. Here's the link:
subject: XStream --> getting "id=someId"
It's not a secret anymore!