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