SitePoint Sponsor

User Tag List

Results 1 to 15 of 15

Thread: Extracting data

  1. #1
    SitePoint Enthusiast dlh1989's Avatar
    Join Date
    Nov 2004
    Location
    Sunshine Coast, QLD, Australia
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Extracting data

    OK, now I know that how to display an XML element in ASP but how do I display an XML attribute in asp? Take http://livescores.afl.com.au/flash/match-10130605.xml for example. If i put
    Code:
    <xml id="game" src="http://livescores.afl.com.au/flash/match-10130605.xml"></xml>
    <table border="1" datasrc="#game">
    <tr>
    <td><span datafld="message"></span></td>
    </tr>
    </table>
    then it will display Recent Head To Head: Bombers 2, Lions 4. How do I get it to display the hg values located in the scoreboard element in ASP?

  2. #2
    SitePoint Enthusiast dlh1989's Avatar
    Join Date
    Nov 2004
    Location
    Sunshine Coast, QLD, Australia
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    anyone?

  3. #3
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use Dom, Xpath.

    e.g.

    Set AttributeItem = Dom.selectNodes("//*/*/@attributename")

  4. #4
    SitePoint Enthusiast dlh1989's Avatar
    Join Date
    Nov 2004
    Location
    Sunshine Coast, QLD, Australia
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, perhaps i should rephrase. I am a beginner, I know little ASP but am trying to learn. How do I do the above?

  5. #5
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    Set Dom = Server.CreateObject("Microsoft.XMLDOM") 
    Dom.async="false"
    Dom.resolveExternals = True;
    Dom.validateOnParse = True;
    Dom.load("xmlfile.xml")
     
     
    'Example...
    Set oNode = Dom.selectNodes("//*/*/@attributename")
    For Each strNode In oNode
    Response.Write(strNode.nodeName & "<br />") 
    Next
     
    Set oNode = Dom.selectNodes("//afl_live/message")
    Set oNode = Dom.selectNodes("//afl_live/stats/player")

  6. #6
    SitePoint Enthusiast dlh1989's Avatar
    Join Date
    Nov 2004
    Location
    Sunshine Coast, QLD, Australia
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I used your code and got the error "Expected End of Statement" so I fixed that by adding "" around both true. But now instead of getting the "Expected End of Statement" error, nothing appears on the page, just white. How do I fix this?

  7. #7
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    Set Dom = Server.CreateObject("Microsoft.XMLDOM")
    Dom.async = False
    Dom.resolveExternals = True
    Dom.validateOnParse = True
    Dom.load("http://livescores.afl.com.au/flash/match-10130605.xml")
    'Checks for Parse Errors
    If (Dom.parseError.errorCode <> 0) Then
    	Dim myErr
    	Set myErr = Dom.parseError
    	Response.Write ("You have error " & myErr.reason)
    	'WScript.Echo("You have error " & myErr.reason)
    Else
    	'WScript.Echo(Dom.Xml)
     
    	'Example...
    	Set oNode = Dom.selectNodes("//afl_live/message")
    	For Each strNode In oNode
    	 StdOut = strNode.nodeName & ": " & strNode.childNodes.Item(0).nodeValue & " (" & strNode.nodeType & ")"
    	 Response.Write(StdOut & "<br />") 
    	 'WScript.Echo(StdOut)
    	Next
     
    	Set oNode = Dom.selectNodes("//afl_live/stats/player")
    	For Each strNode In oNode
    	 StdOut = strNode.nodeName & ": " & strNode.getAttribute("name") & " (" & strNode.nodeType & ")"
    	 Response.Write(StdOut & "<br />") 
    	 'WScript.Echo(StdOut)
    	Next
    End If
    This works...

  8. #8
    SitePoint Enthusiast dlh1989's Avatar
    Join Date
    Nov 2004
    Location
    Sunshine Coast, QLD, Australia
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried that and I got You have error No data is available for the requested resource. How can this be fixed?

  9. #9
    Drupaler bronze trophy greg.harvey's Avatar
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    3,258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have a look at this:
    http://forums.aspfree.com/t47119/s.html
    Or more specifically:
    http://forums.aspfree.com/showpost.p...22&postcount=7

    You have exactly the same issue with Andrew's script. It too works fine on a local copy of the XML file - I just tried it.

    Your solution is here in post 11:
    http://forums.aspfree.com/showpost.p...2&postcount=11

    Save it locally, then work with it.

    Cheers,

    G

  10. #10
    SitePoint Enthusiast dlh1989's Avatar
    Join Date
    Nov 2004
    Location
    Sunshine Coast, QLD, Australia
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, Thanks for that but I still have a problem. I get an error that says Expected 'End' Line 204. I have colored line 204 in red and bold Here is my entire code.
    Code:
    <%
    Function WriteToFile( str_FileName, str_Message )
    Set obj_FSO = Server.CreateObject("Scripting.FileSystemObject")
    Set obj_OutputFile = obj_FSO.OpenTextFile(str_FileName, 2, True, 0)
    obj_OutputFile.WriteLine(str_Message)
    obj_OutputFile.Close
    Set obj_OutputFile = Nothing
    Set obj_FSO = Nothing
    End Function
     
    Function GetURL(str_URL)
    Set obj_XMLHTTP = Server.CreateObject ("MSXML2.ServerXMLHTTP.3.0") 
    obj_XMLHTTP.Open "GET", str_URL, False, "", "" 
    obj_XMLHTTP.Send()
     
    While obj_XMLHTTP.readyState <> 4
    	obj_XMLHTTP.waitForResponse(8000)
    Wend
     
    If Err.Number = 0 Then
    	' Response.Write("Status = " & obj_XMLHTTP.Status & "<br>")
    	If obj_XMLHTTP.Status = 200 Then
    	 str_GetURL = obj_XMLHTTP.ResponseText
    	Else
    	 str_GetURL = "Bad URL"
    	End If
    Else
    	str_GetURL = "Bad URL"
    End If 
    Set obj_XMLHTTP = Nothing 
    GetURL = str_GetURL
    End Function
    %>
    <%
    str_Response = GetURL("http://livescores.afl.com.au/flash/match-10131201.xml")
    If str_Response <> "Bad URL" Then
    WriteToFile Server.MapPath("test.xml"), str_Response 
     
    Set xml = Server.CreateObject("Microsoft.XMLDOM")
    xml.async = False
    xml.load (Server.MapPath("test.xml"))
     
    If xml.parseError.errorCode <> 0 Then
    	Response.Write xml.parseError.reason
    End If
     
    mtchstts = xml.documentElement.childNodes(2).Attributes(12).text
    mtchbrek = xml.documentElement.childNodes(2).Attributes(14).text
     
    If mtchstts = "P" Then
     
    homegoal = 0
    homebehi = 0
    awaygoal = 0
    awaybehi = 0
     
    Else If mtchstts = "L" Then
     
    quarter1 = xml.documentElement.childNodes(3).childNodes(0).Attributes(6).text
    If quarter1 = "N" Then
    ' The 1st quarter isn't complete
    ' It is the 1st quarter 
    	quarter = 0
     
    Else If quarter1 = "Y" And mtchbrek = "Y" Then
    ' The 1st quarter is complete and it's a break
    ' It is Quarter Time
    	quarter = 0
     
    Else If quarter1 = "Y" And mtchbrek = "N" Then
    ' The 1st quarter is complete and it isn't a break
    ' It is the 2nd quarter
    	quarter = 1
    	quarter2 = xml.documentElement.childNodes(3).childNodes(1).Attributes(6).text
     
    Else If quarter2 = "N" Then
    ' The 2nd quarter isn't complete
    ' It is the 2nd quarter	
    	quarter = 1
     
    Else If quarter2 = "Y" And mtchbrek = "Y" Then
    ' The 2nd quarter is complete and it is a break
    ' It is Half Time
    	quarter = 1
     
    Else If quarter2 = "Y" And mtchbrek = "N" Then
    ' The 2nd quarter is complete and it isn't a break
    ' It is the 3rd quarter
    	quarter = 2 
    	quarter3 = xml.documentElement.childNodes(3).childNodes(2).Attributes(6).text
     
    Else If quarter3 = "N" Then
    ' The 3rd quarter isn't complete
    ' It is the 3rd quarter
    	quarter = 2
     
    Else If quarter3 = "Y" And mtchbrek = "Y" Then
    ' The 3rd quarter is complete and it is a break
    ' It is Three Quarter Time
    	quarter = 2
     
    Else If quarter3 = "Y" And mtchbrek = "N" Then
    ' The 3rd quarter is complete and it isn't a break
    ' It is the 4th quarter
    	quarter = 3
    	quarter4 = xml.documentElement.childNodes(3).childNodes(3).Attributes(6).text
     
    Else If quarter4 = "N" Then
    ' The 4th quarter isn't complete
    ' It is the 4th quarter
    	quarter = 3
     
    Else If quarter4 = "Y" Then
    ' The 4th quarter is complete
    ' It is Full Time
    	quarter = 3
     
    End If
     
    End If
     
    homeabbr = xml.documentElement.childNodes(2).Attributes(2).text
    homegoal = xml.documentElement.childNodes(3).childNodes(quarter).Attributes(1).text
    homebehi = xml.documentElement.childNodes(3).childNodes(quarter).Attributes(2).text
    homescor = (homegoal*6) + Int(homebehi)
     
    awayabbr = xml.documentElement.childNodes(2).Attributes(6).text
    awaygoal = xml.documentElement.childNodes(3).childNodes(quarter).Attributes(3).text
    awaybehi = xml.documentElement.childNodes(3).childNodes(quarter).Attributes(4).text
    awayscor = (awaygoal*6) + Int(awaybehi)
     
     
    Set xml = Nothing
    End If
    %>
    <html>
    <head>
    <title></title>
    </head>
    <body bgcolor="#333333">
    <div style="position: absolute; top: 2px; left: 2px; width:; width: 950px; height: 72px;">
    <table cellpadding="0" cellspacing="0" width="100%" border="0">
    <tr>
    <td bgcolor="#333333">
    <%=quarter%>
    </td></tr>
    <tr>
    <td bgcolor="#333333">
    <img src="/afl/images/digital/lrg/<%=homeabbr%>.gif">
    <img src="/afl/images/digital/lrg/space.gif">
    <% if len(homegoal)=1 then %><img src="/afl/images/digital/lrg/space.gif" border="0">&nbsp;<% end if %>
    <% for n = 1 to len(homegoal)
    Response.Write "<img src='/afl/images/digital/lrg/" & mid(homegoal,n,1) & ".gif'>"
    If n < len(homegoal) Then
    	 Response.Write "&nbsp;"
    End If
    next %> 
    <img src="/afl/images/digital/lrg/dot.gif" border="0">
    <% if len(homebehi)=1 then %><img src="/afl/images/digital/lrg/space.gif" border="0">&nbsp;<% end if %>
    <% for n = 1 to len(homebehi)
    Response.Write "<img src='/afl/images/digital/lrg/" & mid(homebehi,n,1) & ".gif'>"
    If n < len(homebehi) Then
    	 Response.Write "&nbsp;"
    End If
    next %> 
    <img src="/afl/images/digital/lrg/dot.gif" border="0">
    <% if len(homescor)=2 then %><img src="/afl/images/digital/lrg/space.gif" border="0">&nbsp;<% end if %>
    <% if len(homescor)=1 then %><img src="/afl/images/digital/lrg/space.gif" border="0">&nbsp;<img src="/afl/images/digital/lrg/space.gif" border="0">&nbsp;<% end if %>
    <% for n = 1 to len(homescor)
    Response.Write "<img src='/afl/images/digital/lrg/" & mid(homescor,n,1) & ".gif'>"
    If n < len(homescor) Then
    	 Response.Write "&nbsp;"
    End If
    next %> 
    </td></tr>
    <tr>
    <td bgcolor="#333333">
    <img src="/afl/images/digital/lrg/<%=awayabbr%>.gif">
    <img src="/afl/images/digital/lrg/space.gif">
    <% if len(awaygoal)=1 then %><img src="/afl/images/digital/lrg/space.gif" border="0">&nbsp;<% end if %>
    <% for n = 1 to len(awaygoal)
    Response.Write "<img src='/afl/images/digital/lrg/" & mid(awaygoal,n,1) & ".gif'>"
    If n < len(awaygoal) Then
    	 Response.Write "&nbsp;"
    End If
    next %> 
    <img src="/afl/images/digital/lrg/dot.gif" border="0">
    <% if len(awaybehi)=1 then %><img src="/afl/images/digital/lrg/space.gif" border="0">&nbsp;<% end if %>
    <% for n = 1 to len(awaybehi)
    Response.Write "<img src='/afl/images/digital/lrg/" & mid(awaybehi,n,1) & ".gif'>"
    If n < len(awaybehi) Then
    	 Response.Write "&nbsp;"
    End If
    next %> 
    <img src="/afl/images/digital/lrg/dot.gif" border="0">
    <% if len(awayscor)=2 then %><img src="/afl/images/digital/lrg/space.gif" border="0">&nbsp;<% end if %>
    <% if len(awayscor)=1 then %><img src="/afl/images/digital/lrg/space.gif" border="0">&nbsp;<img src="/afl/images/digital/lrg/space.gif" border="0">&nbsp;<% end if %>
    <% for n = 1 to len(awayscor)
    Response.Write "<img src='/afl/images/digital/lrg/" & mid(awayscor,n,1) & ".gif'>"
    If n < len(awayscor) Then
    	 Response.Write "&nbsp;"
    End If
    next %> 
    </td></tr>
    </table>
    </div>
    </body>
    </html>
    My aim of the file is to show live scores. Here is another problem that you may find that I tried to fix but I don't know if worked because I am getting the previous problem. Anyway, if you can fix the provious problem maybe you can work out a better way to fix this: When quarter1 = "N" quarter2 doesn't exist. When quarter2 = "N" quarter3 doesn't exist. When quarter3 = "N" quarter4 doesn't exist. When it doesn't exist, I get an error saying that there is an object required (it cant find it in the xml document because it doesn't exist). Is there a way around this problem and how can it be done?
    Last edited by dlh1989; Jun 10, 2005 at 06:32.

  11. #11
    Drupaler bronze trophy greg.harvey's Avatar
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    3,258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Expected End means you forgot to close one of your Ifs. Double-check them and see where.

    G

  12. #12
    SitePoint Enthusiast dlh1989's Avatar
    Join Date
    Nov 2004
    Location
    Sunshine Coast, QLD, Australia
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I couldn't find any Ifs that needed closing so i just added an End If where the "error" was. And I got the same error message but on the next line. So I did it again. And again I got the same error and on the next line. What's going on? and how can this be fixed?

  13. #13
    Drupaler bronze trophy greg.harvey's Avatar
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    3,258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe you've got one End too many, rather than not enough. The error would be the same ...

  14. #14
    SitePoint Enthusiast dlh1989's Avatar
    Join Date
    Nov 2004
    Location
    Sunshine Coast, QLD, Australia
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nope, I fixed it by turning all my Else Ifs into End Ifs. But I may have worked out a way to fix all my problems if someone please tell me how to count the number of elements are in xml.documentElement.childNodes(3) using ASP. Please.
    Last edited by dlh1989; Jun 10, 2005 at 18:42.

  15. #15
    Drupaler bronze trophy greg.harvey's Avatar
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    3,258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You keep referring to Else If's - I ignored this considering it a typo here, but the correct syntax is ElseIf - all one word! You will get errors if you're using "Else If" like that. Looks like that may have been your problem... put your Else If's back as ElseIf's!

    Cheers,

    G


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •