views:

111

answers:

2

I have a template and need to create several xml files. The file contains one variable -this- to replace several times, save it as that name -this-.xml and then repeat for each of the values in my text or excel list or from a database - How would I best go about doing this?

A: 

Are you looking at doing this in code, or using a template-driven generator?

Several choices:

  • inside Visual Studio, you could use a T4 template to achieve this
  • you could use a code generator such as CodeSmith, MyGeneration or others
  • you could write your own little program to do this (in C#, VB - anything)

Which of these are you really looking for?

Marc

marc_s
I am just looking for the simplest way - there's know way that I would be able to write a program to do this - I got the idea form using BK Replaceem and thought I may be able to use a list to kind of do the opposite of that program - Thanks
Well, in that case, I would say have a good look at MyGeneration - it's a template-driven code/textfile generator - you should have no trouble creating your template and then filling in the blanks from a CSV or XML file or something. Go to http://www.mygenerationsoftware.com/
marc_s
+1  A: 

Old school unix way (bash shell syntax):

for var in $(cat replacelist.txt); do sed "s/-this-/$var/g" < template.xml >$var.xml; done
reedstrm
You risk producing not-wellformed XML. At the very least, you should escape $var before!
bortzmeyer
Well, it's a fairly well constrained case: we're not talking something coming from a random user input web form: this is old-school automation of an individual's work: if it breaks, you can keep both pieces.
reedstrm