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>
+ Reply to Thread
Results 1 to 12 of 12
-
-
Code:
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 meIf in doubt, Google it. -
jimmalenko,
Just 1 more thing if you have time. How would i get the filepath to a variable?? See XML above.
Thanks. -
Here's code to get both plot and file Path and is more efficient than what I posted earlier:
Code: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
If in doubt, Google it. -
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? -
I realize this is a really old post. Can you give an example of how to concatenate elements from an xml file into a single string?
Example, I want to read:
<ItemUpdate>
<Item>
<ItemNumber>230462</ItemNumber>
<ItemDescription>Description</ItemDescription>
<ItemPrice>56.92</ItemPrice>
And want the output to write:
"230462,Description,56.92"
Any help is appreciated, thanks. -
use the above script to read each node into a separate variable the declare a third variable where you concat the previous variables.
Code:Dim itmNbr, itmDesc, itmPrice, itemInfo Set xmlDoc = CreateObject("Msxml2.DOMDocument") xmlDoc.load("c:\\test.xml") itmNbr = xmlDoc.getElementsByTagName("ItemNumber").item(0).text itmDesc = xmlDoc.getElementsByTagName("ItemDescription").item(0).text itmPrice = xmlDoc.getElementsByTagName("ItemPrice").item(0).text itemInfo= itmNbr&","&itmDesc&","&itmPrice MsgBox itemInfo
Code:Dim itemInfo Set xmlDoc = CreateObject("Msxml2.DOMDocument") xmlDoc.load("c:\\test.xml") itemInfo= xmlDoc.getElementsByTagName("ItemNumber").item(0).text&","&xmlDoc.getElementsByTagName("ItemDescription").item(0).text&","&xmlDoc.getElementsByTagName("ItemPrice").item(0).text MsgBox itemInfo
Last edited by dragonkeeper; 7th Jun 2012 at 16:13. Reason: corrected syntax error
Murphy's law taught me everything I know. -
hello
i need some help please.
1. I have a folder with multiple xml files that i would like to extract a value (id) from. Can you help me with a script?
all the xml files start like this
Code:<?xml version="1.0" encoding="windows-1252"?> <document> <generalInfo actDBID="318224" actCategorie="Speta" actTip="Sentință civilă" actEmitent="Judecătoria Oradea" actNr="104/2012" actTematica="1163412803" actData="10.01.2012" actCelex="" pubTip="portal.just.ro" pubNr="0" pubData="10.01.2012" actLimba="Romana"/> <workData basePath="" status="9" statusHelp="Din Baza" user="raluca.rizea" comment="Document exportat din Baza"/>
can you help me with this?
2. also i have another problem i need to solve with the xml files (i have about 20.000 files) ... i need to make a replace (based on a list txt file or excel with about 60.000 words) in all the xml files ... is there a solution for this ... no mater the programming language?
thank you -
Since no one else has answered I'll take a stab at helping you, I usually do things of this nature using a a JS file with an HTA wrapped around it. So I can develop it quickly an can edit on the fly without having to depend on an IDE.
First off look at the File System Object.
Use FSO "folder" object and "files" method to generate an array of your file paths.
Next iterate through the array using the File System Obejects "Microsoft.XMLDOM" it you're building this in Internet Explorer that is. You can use the "getElementsByTagName" method to grab all data in the "generalInfo" node then use the "getAttribute" method to get the data in the "actDBID" attribute.
Again this is something I use javascript or perl for wrapped in an HTA IMO JavaScript is easier since you don't have to worry about modules. Javascript is very strong in regard to regular expressions. have a look at the following sites.
Scripting the File System, Part I: The Folder Object - Doc JavaScript - WebReference.com
JavaScript Regular Expressions methods and usage
Mastering Javascript ArraysMurphy's law taught me everything I know.
Similar Threads
-
Can VBscript/Batch read MPEG file?
By Cazz in forum ProgrammingReplies: 11Last Post: 3rd Sep 2010, 07:50 -
WMV to FLV assistance needed
By OM2 in forum Newbie / General discussionsReplies: 0Last Post: 10th Jan 2010, 06:45 -
region code assistance needed with the sony ns-700h dvd player
By stressed_with_sony in forum DVD RippingReplies: 1Last Post: 2nd Jun 2009, 00:53 -
region code assistance needed for the sony dvp ns700h
By stressed_with_sony in forum DVD RippingReplies: 0Last Post: 1st Jun 2009, 20:34 -
Assistance needed converting to WMV for playback on Xbox 360
By eggedd2k in forum Video ConversionReplies: 2Last Post: 16th May 2007, 17:29