[TriLUG] OT: Query/edit XML file

Scott G. Hall ScottGHall at BellSouth.Net
Tue Apr 21 15:44:06 EDT 2009


Matthew Opoka wrote:
> My application dumps a rather large XML file with DTD headers and I need
> to query(regex) and edit the file so it can be re-imported.  Does anyone
> know the easiest and best way to accomplish this task other than with vi
> line by line? The query would be something like this: Search for objects
> with type=sts and name=hostname and value=HOSTA  where hostname only has
> one value.  If found, then add a new lower case variation(hosta) value
> and update the object action from declared to updated.

If you are looking to do this automatically from a program, have you used
the Xerces library yet?  There are versions for C++, Java, PHP, Perl and
so on.  I worked on an application that had to input data from sensor
instruments -- several different instruments from different manufacturers
that generated different XML files (close but not quite the same), and
had to do exactly the type of thing you are doing to massage the XML to
look the same from each instrument.  A few scripting lines, and it worked
like a champ!

-- 
Scott G. Hall
Raleigh, NC, USA
ScottGHall at BellSouth.Net



More information about the TriLUG mailing list