WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

XML
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Searching XML Files


Question:

I need to create a script that will search a list of XML files for a particular tag, then do something with the file depending on the results. All the XML files are in a processing directory called "TEMP". The files are large (between 6 and 12MB, or some 180,000 lines), and new XML files are being added every 10 to 20 minutes.

Answer:

You could try using XMLStarlet, which is a command-line tool that can query and edit XML files without the overhead of the XML DOM or other methods...

XMLStarlet is downloadable from: http://xmlstar.sourceforge.net/

Make sure to place it in the script's folder or within the PATH of your PC...

;Winbatch Version: 2005C -- Script by Jay Alverson

path = DirScript()
FilesToProcess = FileItemize(StrCat(path, "Indicator*.xml"))

editor = "notepad.exe"
comspec = Environment("COMSPEC")
outfile = StrCat(DirScript(), "Out.txt")

For x = 1 To ItemCount(FilesToProcess, @TAB)
   ThisXML = ItemExtract(x, FilesToProcess, @TAB)
   RunHideWait(comspec, `/c xml sel -T -t -m "//CompleteIndicator" -v "." "%ThisXML%" > "%outfile%"`)
   Indicator = FileGet(outfile)
   Message(ThisXML, Indicator)
Next

Exit

Article ID:   W17344
File Created: 2007:07:03:14:29:32
Last Updated: 2007:07:03:14:29:32