How do I create an interface to update an XML template?
July 23, 2007 9:26 AM   Subscribe

How do I go about creating a simple interface to update only certain specific nodes in different XML templates?

I have several XML templates which I use over and over again, updating the same specific nodes every time. At present I just do this by searching for the name of the node in the document, nexting through until I find the right ones, and then pasting in the new text. It strikes me that an interface which asks me to enter only the specific data I need to change and then updates the template for me would be a great great improvement - I do I go about creating such a thing, or where would I go to start learning how to do so?

(One caveat - there are multiple versions of the same nodes within the template, but I only need to update certain ones. So, for example, there are 20 "album" tags, each of which has let's say 10 "song" tags each, but I only need to update the 3rd song of the 5th album every time I reuse the template.)

Although I've never done anything like this before - and I only have basic programming knowledge - I'm *imagining* that creating an interface (a web interface?) which allows me to enter the template path and the new specific data shouldn't be brain surgery. I can learn pretty fast, and I'm looking at this half as a way to make my life easier, and half as a great opportunity to learn how to do something new.
posted by The_Partridge_Family to Computers & Internet (5 answers total)
 
Ignoring the fact that it's XML, you could probably write something in PHP that gets the input from a form and just does the old
echo "<XML etc ec".$_GET['value'].">";
type thing, and spits it out. (note: that example would open you up to XSS if you put it online. it's just a synopsis.)

But I don't see this happening without some knowledge of PHP or a similar scripting language...
posted by tmcw at 9:44 AM on July 23, 2007


Hmm, if you have access to the full office suite, take a look at InfoPath 2007, it very well might do what you need...

Alternatively , What I'm doing right now involves a xml file which has one configurable value based on where the application gets installed to. I replaced that value with @config_dir@ and then just search and replace that text automatically. It would be a 3-4 line script in ruby or perl to find and replace the value with a inputed string and then save off to another file.
posted by cschneid at 9:45 AM on July 23, 2007


the token replacement trick that cschneid mentions is the easiest approach assuming that there is a unique, fixed number of items that you are replacing.

I'd also add that when you replace the token with your text, that you be sure to escape it for characters that are not proper to be appearing in that location of the xml document. This would include characters like > or <.
posted by mmascolino at 10:20 AM on July 23, 2007


Response by poster: hmm - I have InfoPath and it appears to be excellent for *creating* a form to change specific areas of a template, but updating the template seems uber-complicated involving submission to a database or Web server: I just want it to update an XML file on my desktop!
posted by The_Partridge_Family at 12:11 PM on July 23, 2007


That sounds like a relatively simple XSL transformation.

I say "sounds like" because it's only simple if you can reduce the requirements for which bits of data you're changing to a simple formula.

Are your updating tasks easy to codify, as in, will it always be something like this?
"attribute 'length' of song where 
number = X of album where name = Y 
needs changing to '<new data>'" 
If you can always reduce your needs to the same list of parameters (attribute-name, song-number, album-title, new data) then it will be easy.
posted by AmbroseChapel at 12:22 AM on July 24, 2007


« Older Help an inexperienced bridesmaid plan a...   |   Nice, but not expensive, suits in NYC Newer »
This thread is closed to new comments.