VideoHelp Forum




+ Reply to Thread
Results 1 to 12 of 12
  1. 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>
    Quote Quote  
  2. VH Veteran jimmalenko's Avatar
    Join Date
    Aug 2003
    Location
    Down under
    Search PM
    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 me
    If in doubt, Google it.
    Quote Quote  
  3. jimmalenko,

    Thank you much appreciated. It works great
    Quote Quote  
  4. jimmalenko,

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

    Thanks.
    Quote Quote  
  5. VH Veteran jimmalenko's Avatar
    Join Date
    Aug 2003
    Location
    Down under
    Search PM
    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.
    Quote Quote  
  6. Thanks,

    Using your method I can select anything from the xml.
    Quote Quote  
  7. VH Veteran jimmalenko's Avatar
    Join Date
    Aug 2003
    Location
    Down under
    Search PM
    Originally Posted by NYPlayer
    Thanks,

    Using your method I can select anything from the xml.
    Exactly
    If in doubt, Google it.
    Quote Quote  
  8. Member
    Join Date
    Oct 2009
    Location
    Germany
    Search Comp PM
    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?
    Quote Quote  
  9. 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.
    Quote Quote  
  10. Member dragonkeeper's Avatar
    Join Date
    Jul 2003
    Location
    United States
    Search Comp PM
    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
    It can be done with one variable as well; but the above is easier to read.
    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.
    Quote Quote  
  11. Member
    Join Date
    Oct 2012
    Location
    Bucharest
    Search PM
    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"/>
    i need to extract the data from actDBID (318224) from all the files and put it in a txt file, excel file ...

    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
    Quote Quote  
  12. Member dragonkeeper's Avatar
    Join Date
    Jul 2003
    Location
    United States
    Search Comp PM
    Originally Posted by iorasuke View Post
    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?
    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.


    Originally Posted by iorasuke View Post

    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"/>
    i need to extract the data from actDBID (318224) from all the files and put it in a txt file, excel file ...



    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?
    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 Arrays
    Murphy's law taught me everything I know.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!