Reading XML Files in WSH
(Page 1 of 6 )
In my last article I showed you how you can use Microsoft’s XML Parser to create XML documents in WSH. Today I’m going to show you how to use your scripts to read information from XML files.
You’re going to need a copy of the XML file that you created in my last article. If you don’t have one, you can download an example XML file here. This is a sample XSPF audio playlist. XSPF is an XML-based playlist specification designed to be easily portable and cross-platform compatible.
<?xml version="1.0" encoding="UTF-8"?>
<playlist version="1" xmlns="http://xspf.org/ns/0/">
<trackList>
<track>
<location>http://www.nilpo.com/pub/tracks/Breaking%20Benjamin%20-%20The%20Diary%20of%20Jane.mp3</location>
<title>The Diary Of Jane</title>
<creator>Breaking Benjamin</creator>
<info>http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewAlbum?i=171774391&id=171774379&s=143441</info>
<album>Phobia</album>
<trackNum>2</trackNum>
</track>
<track>
<location>http://www.nilpo.com/pub/tracks/The%20Rising%20-%20Who%20You%20Are.mp3</location>
<title>Who You Are</title>
<creator>The Rising</creator>
<info>http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewAlbum?i=275505564&id=275505471&s=143441</info>
<album>Future Unknown</album>
<trackNum>10</trackNum>
</track>
</trackList>
</playlist>
Its structure is relatively simple. A playlist element houses a track listing that contains each of the tracks in the playlist. Each track has its own set of elements that contain properties about that track.
Remember that XML files are simple database structures. So it’s best to think of an XML file as you would a database. That mentality will make this a little easier to understand for most system administrators, so that’s the approach I’ll be taking in this article. As you will soon see, with the help of the XML Parser, an XML file becomes far more than a simple text file. It actually allows us to create queries for returning specific information—and that sounds more like a database to me!
Next: Getting started >>
More Windows Scripting Articles
More By Nilpo