• 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

Generating XML from template file.

 
Ranch Hand
Posts: 1140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to generate XML documents dynamically from a template file and a flat file containting the values

For example, say I have a Template like this

And the flat file will have something like

I need to merge these 2 files and get the following output

What are all the possible ways to do this?
Are there any tools available to do this?
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's something to start from:
 
Mani Ram
Ranch Hand
Posts: 1140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply Lasse.
I should have explained it bit clearly in my initial post. Actually I was looking for various possible ways to acheive this. Using Java is one way, but is there some other way?
I need this tool to be as generic as possible. It should be possible for me to modify the variable file and / or the template file with out changing the code.
I could very well use your logic and create this utility, but I would like to check if there are any tools available to acheive the same.
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about using simple variable placeholders like <some-element>@myvariable@</some-element> and run a brutal search-and-replace over the whole document? That should work regardless of how the template is changed as long as the expected variable placeholders are found somewhere within the document. Similarly, you wouldn't need to touch the code unless you change the way you mark-up your variable placeholders.
reply
    Bookmark Topic Watch Topic
  • New Topic