• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to use JAXB  RSS feed

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I need to tranformation the txt files into xml files, but each row txt files don't have same elements, for example the first book is composite one author
<books>
<book>Title</book>
<price>price</price>
<author>Author</author>
</books>

but the second book is composite two author
<books>
<book>Title</book>
<price>price</price>
<author>Author</author>
<author>Author2</author>
</books>


I would have the xml files with the number of authors variables, I can use JAXB for my problem?or not? can you help me?
Thanks
 
Bartender
Posts: 1840
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't quite understand what you mean by "transform txt files into xml files. Xml files are text files - they just get interpreted in a special way.
Both examples you have given are valid XML, if a little funny.

Certainly you can use JAXB to map between Javabeans and this XML.
You just need to have a Collection/List of attributes for any repeating items rather than actual type.
i.e. rather than


you could have


That way you could have multiple authors defined.


Also, I think it would make more sense like
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!