• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to use JAXB

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
When you have exhausted all possibilities, remember this: you haven't - Edison. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic