Announcement

Collapse
No announcement yet.

XML Data Refresh

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • XML Data Refresh

    Hello Again All,

    I have a script to parse XML data and it works fine, but i need the script to check the XML file every 5 seconds from the website. Right now it only runs once when i execute the script. Has anyone done this before?

    Thanks in advance,
    Shotski

  • #2
    One way to check for updates would be to have a looping director with a action keyframe. This action keyframe can call your Data Refresh subroutine.
    THIS_SCENE*TREE*<path to your script container>*SCRIPT INVOKE <name of Data Refresh sub rutine>;

    I am looking for a good way to parse XML - are you willing to share your script?

    regards
    jogvan olsen
    Attached Files

    Comment


    • #3
      Simple and elegant way.

      PHP Code:
      dim timer,limit as integer

      timer 
      0

      limit 
      100  'Set your limit.

      sub OnExecPerField()

         timer = timer + 1

         if timer >= limit then

         '
      Write your function here
        
         timer 
      0

         end 
      if

      end sub 

      Comment


      • #4
        Hi Jogvan,

        The script below is what i used. I modified it for my use. I got it on this forum from the great folks here that are always such a great help:

        dim result as string
        Dim url as string = "www.yourURL.com"
        Dim page as string = "/url continued"

        Dim RaceID as Container = Scene.FindContainer("RaceID")
        Dim RaceName1 as Container = Scene.FindContainer("RaceName1")
        Dim RaceName2 as Container = Scene.FindContainer("RaceName2")

        '--------- CANDIDATE 1 -------------------------
        Dim Cand1_ID as Container = Scene.FindContainer("Candidate1_ID")
        Dim Cand1_Display_Order as Container = Scene.FindContainer("Candidate1_Display_Order")
        Dim Cand1_Visible as Container = Scene.FindContainer("Candidate1_Visible")
        Dim Cand1_FirstName as Container = Scene.FindContainer("Candidate1_First_Name")
        Dim Cand1_LastName as Container = Scene.FindContainer("Candidate1_Last_Name")

        '--------- CANDIDATE 1 -------------------------

        result = system.TcpSend(url, 80, "GET "&page&"\n\n", 900)

        'this function takes a string of xml data, an xml node name and returns everything in that node
        function GetXMLText(ByVal dataString as string, ByVal DATA as string) as string
        dim startNode, endNode as string
        startNode = "<" & DATA & ">"
        endNode = "</" & DATA & ">"


        if dataString.find(startNode) <> -1 then
        dataString.Erase(0, dataString.find(startNode) + Len(startNode))
        dataString.Erase(dataString.find(endNode), len(dataString))
        GetXMLText = dataString
        else
        GetXMLText = ""
        end if

        end function

        sub OnEnter()
        end sub

        'sub OnExecPerField()
        sub OnInitParameters()
        println result

        RaceID.Geometry.Text = GetXMLText(result, "RACE_ID") & " - Race ID"
        RaceName1.Geometry.Text = GetXMLText(result, "RACE_NAME1")
        RaceName2.Geometry.Text = GetXMLText(result, "RACE_NAME2")


        '----------------- CANDIDATE 1 -----------------
        Cand1_ID.Geometry.Text = GetXMLText(result, "CAND1_CANDIDATE_ID") & " - Candidate 1 ID"
        Cand1_Display_Order.Geometry.Text = GetXMLText(result, "CAND1_DISPLAY_ORDER") & " - Candidate 1 Display Order"
        Cand1_Visible.Geometry.Text = GetXMLText(result, "CAND1_VISIBLE") & " - Candidate 1 Visible"
        Cand1_FirstName.Geometry.Text = GetXMLText(result, "CAND1_FIRST_NAME") & " - Candidate 1 First Name"
        Cand1_LastName.Geometry.Text = GetXMLText(result, "CAND1_LAST_NAME") & " - Candidate 1 Last Name"




        end sub
        '-----------------------------------------

        Comment


        • #5
          Thanks meret,

          i will try that!!

          Comment


          • #6
            Hi meret,

            I tried the script but i am not sure where to put it where i don't get an error. A sample of the script is placed in earlier posts. Thanks for the help in advance

            Comment


            • #7
              I add simple example.
              Attached Files

              Comment


              • #8
                Thanks meret,

                The problem i am having is that i need the script to go to the website and refresh the info. The issue is that i get an error when trying to fit it into this structure:

                result = system.TcpSend(url, 80, "GET "&page&"\n\n", 900)

                'this function takes a string of xml data, an xml node name and returns everything in that node
                function GetXMLText(ByVal dataString as string, ByVal DATA as string) as string
                dim startNode, endNode as string
                startNode = "<" & DATA & ">"
                endNode = "</" & DATA & ">"


                if dataString.find(startNode) <> -1 then
                dataString.Erase(0, dataString.find(startNode) + Len(startNode))
                dataString.Erase(dataString.find(endNode), len(dataString))
                GetXMLText = dataString
                else
                GetXMLText = ""
                end if

                end function

                Comment


                • #9
                  Got it. I used the loop scene you sent earlier. Thanks meter!!!!!

                  Comment


                  • #10
                    Sorry got the name wrong meret!!!

                    Comment


                    • #11
                      You are welcome...

                      Comment


                      • #12
                        Hi Shotski

                        Thank you for sharing your script - look nice, I will try it later.

                        In the meentime I came across this 'vsl-xml-parser' implemented by Rune Bjerke.

                        If works fine when the xml-tree has only one level, and it also handles attributes. But I can't get it parse multilevel xml files.

                        Se more here:
                        http://forum.vizrt.com/forum/viz-art...ring-is-caring

                        Script can be downloadet here:
                        https://github.com/sp00x/vsl-xml-parser

                        regards
                        jogvan olsen

                        Comment


                        • #13
                          Yes the XML i shared works best if there is one level and things are tagged. I am not too versed with scripting so it gets overwhelming. But this worked well for me so far. It would be helpful to have samples scenes that are parsing information so we could learn from them. I know there is an old archive that is shared often about data parsing but its several years old. If you can share your solution it would help me learn as well.

                          Comment


                          • #14
                            There is an issue with using TCPSend though. When it is triggered there is a pause in the scene and in any animation that plays. Is using TcpSendAsync a better way? If so how do i set that up? Also how do you get this to work with transition logic. When i tried using the TPCSend script in the callup scene it did not trigger in transition logic.

                            Comment

                            Working...
                            X