File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XStream --> getting "id=someId"" Watch "XStream --> getting "id=someId"" New topic
Author

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..

THx
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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)

Greetings
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12760
    
    5
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

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.

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 ]
 
 
subject: XStream --> getting "id=someId"
 
Similar Threads
Using XSLT, how do I copy nodes, tags and all?
how to create xml file with forum content
XML Parsing help needed
Generating XML from template file.
Struts2 and XML subnodes to show database relationships?