The Joel on Software Discussion Group (CLOSED)

A place to discuss Joel on Software. Now closed.

This community works best when people use their real names. Please register for a free account.

Other Groups:
Joel on Software
Business of Software
Design of Software (CLOSED)
.NET Questions (CLOSED)
TechInterview.org
CityDesk
FogBugz
Fog Creek Copilot


The Old Forum


Your hosts:
Albert D. Kallal
Li-Fan Chen
Stephen Jones

XML editor for multiple files

I've got a large number of XML files, all with the same structure (same elements/attributes etc).

There's often a need to change the same attribute in each file to the same value. Obviously, it's quite tedious to open them up one by one, locate the attribute in the correct element, and change its value. Also, there's quite a large risk of error.

Now, before I run off and write my own tool to do this, I just wanted to check if anyone know of an existing tool that would allow me to do this, to set an attributes value to the same thing in several files in one go?
Mattias Gustavsson
Tuesday, February 28, 2006
 
 
Pretty much any text editor worth its salt will be able to do a search and replace across multiple files...
Mat Hall Send private email
Tuesday, February 28, 2006
 
 
You don't even need an editor just the regular Cygnus/*nix tools.
Simon Lucy Send private email
Tuesday, February 28, 2006
 
 
I think that probably comes under the "roll your own" heading. :)
Mat Hall Send private email
Tuesday, February 28, 2006
 
 
Use regular expresions and/or confirmation to keep from deleting similar attributes when you search and replace in multiple files.
Nonymous
Tuesday, February 28, 2006
 
 
Ok, just to clarify: I know you can do a search and replace in files using regular expressionswith some existing tools.

What I'm looking for is something specifically designed for XML files, allowing you to select an element and an attribute within it, and change it across all selected files.

This will be done very frequently (some people might even be doing this all day every day), and by people who would not be comfortable with regular expressions or other more advanced ways of doing it. It also needs to be safe, so that it is not possible to mess up the actual XML file structure (just the values should be changeable).

Most likely, there won't be a tool just like this, and I know that writing my own is the only way to get it just the way I want it, but if anyone have come across a tool that does somthing similar, I'd certainly like to have a look at it :-)
Mattias Gustavsson
Tuesday, February 28, 2006
 
 
Erm, write a bit of XSL to do this?
XXX
Tuesday, February 28, 2006
 
 
+1  write a bit of XSL to do this?

Probably the best way to do it in my opinion.  Write an XSLT template and then use perhaps a batch file to orchestrate the process on all the files.
Mike Stephenson Send private email
Tuesday, February 28, 2006
 
 
The XML shell at http://xsh.sourceforge.net/ might be helpful -- not an editor, but a way to do batch XPath search-and-replace that might be a bit more lightweight than XSL.
Eli
Tuesday, February 28, 2006
 
 
You could whip up a script with Mozilla Rhino and E4X to do it. The script would load the files as xml and then loop through each to change the xml, then spit the xml files back out. Rhino works from the command line. On windows a batch file or custom action can help automate the process. I have things setup so I can select a group of files, select a custom action from the context menu, and run a predefined script over the selected files. It's a pleasure to use.
Nonymous
Tuesday, February 28, 2006
 
 
Move it into a relational database, then use an UPDATE statement. I try to avoid XML at all costs.
Steve Hirsch Send private email
Tuesday, February 28, 2006
 
 
How about XMLTk http://xmltk.sourceforge.net/ "a number of utilities that perform simple operations on XML files. We have built a sort utility, an aggregation utility, a mapping utility to transform Unix directory hierarchies to XML, and some smaller utilities. Utilities can be combined sequentially, in pipes, to perform more complex XML processing."

(or possibly Pyxie http://www.xml.com/pub/a/2000/03/15/feature/index.html)
Ian G Send private email
Tuesday, February 28, 2006
 
 
+1 to regular expressions ... I'd use sed (the stream editor)  within a shell script to process the files as a batch.
Steve Moyer Send private email
Tuesday, February 28, 2006
 
 
How about XQuery? http://dsd.lbl.gov/nux/
genius
Tuesday, February 28, 2006
 
 
xmlstarlet might help too : http://xmlstar.sourceforge.net/
motdiem Send private email
Sunday, March 05, 2006
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz