No announcement yet.

parsing XML in template Wizard

  • Filter
  • Time
  • Show
Clear All
new posts

  • parsing XML in template Wizard

    Hi Guys,

    I am trying to figure out how to parse an xml from Viz One. The information i need is in the Picfilename when i choose the clip in Template Wizard. I just need a script to parse it.

    The bold type is the information i need:
    <?xml version="1.0" encoding="utf-8"?><entry xmlns=""><id>urn:vme:scripps-central:asset:2101607280002512321</id><title type="text">TRAFFIC ALERT</title><updated>2016-08-04T18:02:15Z</updated><author><name>SYSTEM+admin</name></author>

    Thanks in advance for the help.

  • #2
    This is example for reading xml in pilot.

    Dim XMLName, XMLTemp
    Dim timervalue
    timervalue = 50
    updatevalue = 50
    Sub LoadXml()
    Set XMLName = CreateObject("Microsoft.XMLDOM")
    Set XMLTemp = CreateObject("Microsoft.XMLDOM")
    if XMLName.Load("I:\weather\locations.xml") And XMLTemp.Load("I:\weather\day.xml") then
    TWUniButton2.Enabled = true
    call LoadData()
    TWUniLabel7.caption="Xml couldn't load from server. Try backup."
    TWUniButton2.Enabled = false
    end if
    End sub
    Sub LoadData()
    call GetValue1("101880252")
    call GetValue1("101816670")
    call GetValue1("101609350")
    call GetValue1("101819729")
    call GetValue1("101642911")
    call GetValue1("101735161")
    call GetValue1("101701668")
    call GetValue1("101853909")
    call GetValue1("101871859")
    call GetValue1("101835848")
    call GetValue1("102147714")
    call GetValue1("101668341")
    call GetValue1("101850147")
    Set XMLName = Nothing
    Set XMLTemp = Nothing
    End Sub
    Sub GetValue1(CityId)
    Dim Name,Value
    Set Name = XMLName.documentElement
    Set Value = XMLTemp.documentElement
    Set NameNodes = Name.selectNodes("//loc[@id="&CityId&"]")
    if NameNodes.length > 0 then
    for Each NameNode In NameNodes
    name = NameNode.Attributes.getNamedItem("name").Text
    Set ValueNodes = Value.selectNodes("//loc[@id="&CityId&"]/step[0]")
    for Each ValueNode In ValueNodes
    icontext = ValueNode.Attributes.getNamedItem("s").Text
    temp1 = ValueNode.Attributes.getNamedItem("tx").Text
    temp2 = ValueNode.Attributes.getNamedItem("tn").Text
    templast = Round((Int(temp1) + Int(temp2))/2)
    TWUniLabel7.caption="There is problem about xml."
    TWUniButton2.Enabled = false
    End if
    End sub


    • #3
      You can edit it your self. Pilot use Xpath for reading xml tag.
      Maybe This link helps you.


      • #4
        Thanks. Is there a way to Trim text in a text box in Template wizard? Basically i am trying to Trim the text to get rid of some extra characters.


        • #5
          what are you trying to trim? if it is empty spaces then the command could be:
          twedit1.text = trim(twedit1.text)


          • #6
            Im trying to trim anything after the bold text. The bold text is always a different length though.
            TRAFFIC ALERT</title><updated>2016-08-04T18:02:15Z</updated><author><name>SYSTEM+admin</name></author>

            So basically i just want this: TRAFFIC ALERT


            • #7
              The other thing i am trying to do is feed this XML into a dropdown in Template Wizard:
              <?xml version="1.0" encoding="UTF-8"?>
              <a>XML Item 1a</a>
              <b>XML Item 1b</b>
              <a>XML Item 2a</a>
              <b>XML Item 2b</b>
              <a>XML Item 3a</a>
              <b>XML Item 3b</b>
              <a>XML Item 4a</a>
              <b>XML Item 4b</b>
              <a>XML Item 5a</a>
              <b>XML Item 5b</b>


              • #8
                In the world of scripting there is alot of way on how to trim that, But based on the sentence in question that you posted there the first thing that came to mind (considering that the BOLD sentence could be of any length) . You could create an array and split the String by the character '<' . If you pulled the text as lines, the bold text is the first set of elements on a new line before the xml code. So split the string by lines "vbLf" . now you have the second line data and if you split that by the '<' and then you just take the first element of that new array which would be the bold text. As for the XML to dropdown, you will use xPath to acess all elements For Each item in items/item/a and items/item/b create an array and push the array elements to the dropdown.items field.


                • #9
                  Do you have any examples i could use? I found a script in the forum but having a few issues. The XML info is below. I need the Name to go to one dropdown and the twitter, facebook & email info to change when an option in another dropdown is chosen. For example, Name, then if i choose Twitter, the Twitter handle populates, else if i choose facebook the Facebook handle populates. I'm not great at scripting so any help would be greatly appreciated.


                  --------------------XML FEED------------------------
                  <?xml version="1.0" encoding="UTF-8"?>
                  <a>FirstName LastName1</a>
                  <a>FirstName LastName2</a>
                  <a>FirstName LastName3</a>
                  <a>FirstName LastName4</a>
                  <a>FirstName LastName5</a>

                  'sub InitForm
                  ' GetXmlClick(Sender)
                  'end sub

                  dim Table(100)

                  Sub GetXmlClick(Sender)
                  dim XmlDom, TalentName, Content1, Content2, Content3, URL
                  Set XmlDom = CreateObject("Microsoft.XMLDOM") 'create xml connection

                  URL="C:\vizrt\DataIntegration\Import_Talent.xml" 'xml to use

                  dim i
                  i = 1
                  j = 1
                  k = 1

                  set TalentName = XmlDom.selectNodes("items/item/a") 'get all title nodes
                  set Content1 = XmlDom.selectNodes("items/item/b") 'get all content nodes
                  set Content2 = XmlDom.selectNodes("items/item/c") 'get all content nodes
                  set Content3 = XmlDom.selectNodes("items/item/d") 'get all content nodes

                  TTDrop.Items.Add = "Choose Talent..."
                  TTDrop.ItemIndex = 0
                  SocialDrop.ItemIndex = 0

                  for each x in TalentName 'go through list of titles
                  Listbox1.items.add x.text 'add title text to listbox
                  TTDrop.Items.Add = x.text

                  for each x in Content1 'go through list of content
                  Table(i) = x.text 'add title text to array

                  for each x in Content2 'go through list of content
                  Table(j) = x.text 'add title text to array

                  for each x in Content3 'go through list of content
                  Table(k) = x.text 'add title text to array

                  End sub

                  Sub ClearListClick(Sender)
                  Listbox1.items.clear 'clear the listbox for data
                  End sub

                  Sub ListBox1Click(Sender)
                  if SocialDrop.ItemIndex = 0 then
                  Story.text = Table(TTDrop.itemindex(i))

                  elseif SocialDrop.ItemIndex = 1 then
                  Story.text = Table(TTDrop.itemindex(j))

                  elseif SocialDrop.ItemIndex = 2 then
                  Story.text = Table(TTDrop.itemindex(k))

                  'Story.text = Table(TTDrop.itemindex)

                  end if
                  End sub


                  • #10
                    This link can help you for spliting text. You can use string and array functions.


                    Split finction is suitable for this problem in array fumction. But i think xml reading is healthy way


                    • #11
                      Hi There,

                      From your explanation i took your Template and created the following logic..... First of all, You dont really need the Get Xml button since the template automatically loads the xml when its opened, i left it there because maybe updates happen often then you can hit the Get Xml button to load the latest values...

                      This template reads the xml you gave as an example... Then it has 2 dropdowns... The candidate names are in the first one, You select the candidate name you want...
                      2- Then you have a second dropdown that allows you to select( Facebook or Twitter or Email).. There is a textbox below that , which will show the Facebook/Twitter/Email info of the selected account depending on the dropdown you selected.

                      Let me know if this worked for you and is the way you wanted it to be, i rebuilt the code to be more straight forward and make sense using Lists.

                      My template is currently pointing to URL="C:\feed\Import_Talent.xml"
                      you would want to change that to the location where your file is sitting. LINE 52

                      I saved the Template Wizard Template as a file.....
                      You can find the file here --Open your template wizard, and select "Import From File" and import this file to test

                      Last edited by Novacane89; 09-18-2017, 11:04 AM.


                      • #12
                        Thanks for all the help guys. I now have a few options to try out!!!! Thanks so much!!!!