PDA

View Full Version : Problem loading XML data (updated)


Keltoi
02-07-2009, 05:07 PM
I'm going to post this here as I'm programming in ASP, though the error would seem to with parsing the XML data.

The error message I'm getting is: The system cannot find the path specified.

Here's the code:<%
Response.Buffer = True
Dim xml, results
Set xml = Server.CreateObject("Microsoft.XMLHTTP")

xml.Open "GET", "http://search.twitter.com/search.atom?q=hello&rpp=1", False
xml.setRequestHeader "Content-Type", "content=text/html; charset=iso-8859-1"
xml.setRequestHeader "User-Agent", "MySearch"
xml.Send

Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load xml.responseText
If objXMLDoc.parseError.errorCode <> 0 then
Response.Write "there was an error: " & objXMLDoc.parseError.reason
Response.End()
End If
Set results = objXMLDoc.documentElement
Set NodeList = results.getElementsByTagName("entry")
For Each Elem In NodeList
Response.Write Elem.selectSingleNode("id").text & "<br />"
Next
Set objXMLDoc=Nothing
Set xml = Nothing
%>

and here's an example of the XML:<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns:google="http://base.google.com/ns/1.0" xml:lang="en-US" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns="http://www.w3.org/2005/Atom" xmlns:twitter="http://api.twitter.com/">
<id>tag:search.twitter.com,2005:search/hello</id>
<link type="text/html" rel="alternate" href="http://search.twitter.com/search?q=hello"/>
<link type="application/atom+xml" rel="self" href="http://search.twitter.com/search.atom?q=hello&amp;rpp=1"/>
<title>hello - Twitter Search</title>
<link type="application/opensearchdescription+xml" rel="search" href="http://search.twitter.com/opensearch.xml"/>
<link type="application/atom+xml" rel="refresh" href="http://search.twitter.com/search.atom?q=hello&amp;rpp=1&amp;since_id=1186618046"/>
<warning>adjusted since_id, it was older than allowed</warning>

<updated>2009-02-07T16:40:12Z</updated>
<openSearch:itemsPerPage>1</openSearch:itemsPerPage>
<openSearch:language>en</openSearch:language>
<link type="application/atom+xml" rel="next" href="http://search.twitter.com/search.atom?max_id=1186618046&amp;page=2&amp;q=hello&amp;rpp=1"/>
<entry>
<id>tag:search.twitter.com,2005:1186618046</id>
<published>2009-02-07T16:40:12Z</published>

<link type="text/html" rel="alternate" href="http://twitter.com/lauzrox/statuses/1186618046"/>
<title>@zane_lowe hello:)</title>
<content type="html">&lt;a href="http://twitter.com/zane_lowe"&gt;@zane_lowe&lt;/a&gt; &lt;b&gt;hello&lt;/b&gt;:)</content>
<updated>2009-02-07T16:40:12Z</updated>

<link type="image/png" rel="image" href="http://s3.amazonaws.com/twitter_production/profile_images/76229215/mee_in_the_snow_normal.jpg"/>
<author>
<name>lauzrox (lauren Edwards)</name>
<uri>http://twitter.com/lauzrox</uri>
</author>
</entry>
</feed>

The XML looks fine to me, has anyone any ideas on what is going on (and hopefully a fix)

Many thanks

Justin

Keltoi
02-07-2009, 10:15 PM
Well after hours of fighting this (it works with other feeds), I've taken a slightly different tact.
For archive purposes here's the working (so far) solution:<%
Response.Buffer = True

Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.setProperty "ServerHTTPRequest", true
objXMLDoc.load trim("http://search.twitter.com/search.atom?q=hello&amp;rpp=1")
If objXMLDoc.parseError.errorCode <> 0 then
Response.Write "there was an error: " & objXMLDoc.parseError.reason
Response.End()
End If
Set objLst = objXMLDoc.getElementsByTagName("feed/entry/*")

For i = 0 to (objLst.length-1)

If objLst.item(i).nodeName = "id" Then Response.Write objLst.item(i).text & "<br />"

Next

Set objXMLDoc=Nothing
%>

Old Pedant
02-11-2009, 01:00 AM
One thing you might try, using your original code, is move away from the old (very old) "Microsoft.xxx" objects.

Try:
Set xml = Server.CreateObject("msxml2.ServerXMLHTTP")

xml.Open "GET", "http://search.twitter.com/search.atom?q=hello&rpp=1", False
xml.Send

Set objXMLDoc = Server.CreateObject("msxml2.DomDocument")
objXMLDoc.load xml.responseXML.xml
...

Note that I did *NOT* tell the ServerXMLHTTP object that I was loading "text/html" because I'm not loading HTML at all. I'm loading XML. No, I don't know if that matters.

I use this code to read RSS feeds and it works just fine.