Forum archive - VBScript to read XML. Assistance Needed

http://www.supermediastore.com/



Forum Archive Home -> Programming -> VBScript to read XML. Assistance Needed



VBScript to read XML. Assistance Needed

NYPlayer posted 2006 Jul 10 10:00
I need some help parsing a XML file with a script. I would like to get just the description data and put it into "Plot" variable. I got it working somewhat but I cannot pull of just the description. It grabs the whole showlist. I tried using description as my node but it doesn't work.

See Script and xml sample below.



script

Dim objXML, Root, x

set objXML = CreateObject("Microsoft.XMLDOM")
objXML.async = "false"
objXML.load("E:\sage2\DesperateHousewives-MyHeartBelongstoDaddy-404318-0.mpg.xml")
Set Root = objXML.documentElement

For Each x In Root.childNodes

if x.nodename="showList" then
plot=x.text
msgbox plot
end if
Next





xml sample

<?xml version="1.0" encoding="utf-8"?>
<sageShowInfo version="1.1">
<channelList>
<channel channelId="10334">
<channelName>KATU</channelName>
<channelDescription>KATU Portland, OR</channelDescription>
<channelNetwork>ABC Affiliate</channelNetwork>
<channelNumber>2</channelNumber>
</channel>
</channelList>
<favoriteList>
<favorite favoriteId="383397">
<title>Desperate Housewives</title>
<firstRun/>
<reRun/>
<autoDelete/>
</favorite>
</favoriteList>
<showList>
<show epgId="EP6723180028">
<title>Desperate Housewives</title>
<episode>My Heart Belongs to Daddy</episode>
<category>Drama</category>
<description>Gabrielle causes a prison riot while visiting Carlos; Lynette learns that Parker has an imaginary friend; Susan helps Mike search for Zach.</description>
<peopleList>
<person role="Actor">Teri Hatcher</person>
<person role="Actor">Felicity Huffman</person>
<person role="Actor">Marcia Cross</person>
<person role="Actor">Eva Longoria</person>
<person role="Actor">Nicolette Sheridan</person>

</peopleList>
<language>English</language>
<originalAirDate>2005-10-17T00:00:00.00Z</originalAirDate>
<airing sageDbId="404318" startTime="2006-07-10T04:00:00.00Z" duration="3600" channelId="10334" favoriteId="383397">
<parentalRating>TV14</parentalRating>
<ratings>
<rating>TV14</rating>
</ratings>
<extraDetails>Closed Captioned, Stereo, SAP</extraDetails>
<mediafile sageDbId="474807" type="TV" startTime="2006-07-10T04:00:00.70Z" duration="3599">
<segmentList>
<segment startTime="2006-07-10T04:00:00.70Z" duration="3599" filePath="E:\sage2\DesperateHousewives-MyHeartBelongstoDaddy-404318-0.mpg"/>
</segmentList>
</mediafile>
</airing>
</show>
</showList>
</sageShowInfo>



jimmalenko posted 2006 Jul 11 06:55
:
Dim xmlDoc, objNodeList, plot

Set xmlDoc = CreateObject("Msxml2.DOMDocument")
xmlDoc.load("c:\inetpub\wwwroot\test.xml")
Set objNodeList = xmlDoc.getElementsByTagName("description")

If objNodeList.length > 0 then
For each x in objNodeList
plot=x.Text
msgbox plot
Next
Else
msgbox chr(34) & "description" & chr(34) & " field not found."
End If




Works for me :)



NYPlayer posted 2006 Jul 11 08:31
jimmalenko,

Thank you much appreciated. It works great



NYPlayer posted 2006 Jul 12 22:05
jimmalenko,

Just 1 more thing if you have time. How would i get the filepath to a variable?? See XML above.

Thanks.



jimmalenko posted 2006 Jul 12 22:42
Here's code to get both plot and file Path and is more efficient than what I posted earlier:

:
Dim description, filepath

Set xmlDoc = CreateObject("Msxml2.DOMDocument")
xmlDoc.load("c:\test.xml")

Set ElemList = xmlDoc.getElementsByTagName("segment")
filepath = ElemList.item(0).getAttribute("filePath")
MsgBox filepath

Set ElemList = xmlDoc.getElementsByTagName("description")
plot = ElemList.item(0).Text
MsgBox plot



NYPlayer posted 2006 Jul 13 15:17
Thanks,

Using your method I can select anything from the xml.



jimmalenko posted 2006 Jul 13 15:55
NYPlayer :
Thanks,

Using your method I can select anything from the xml.


Exactly :D



beagle1234 posted 2009 Oct 04 15:11
On this same topic I am trying to use VBScript to have a user enter in a Date, than use that date to be placed at the end of url to GET an XML file. Once I capture that XML file I would like to parse out data. I have the GET request working, but it is not getting the user input data and I am having trouble parsing the data.

For the parse I want to grab information like the one posted above, and place that data in another text file.

Can anyone help me out?




Login/Register to our forum to be able to post here.








DVDFab DVD to DVD lets you backup DVDs to DVDr, AVI or MP4 for portable devices. More info or download trial!
About   Advertise   Forum Archive   RSS Feeds   Statistics