PDA

View Full Version : GetElementsByTagName doesn't return results.


BarrMan
03-05-2007, 08:26 PM
Hey, I'm using the following code:

Dim xml, obj, url
url = 'page's url in here.
Set xml = Server.CreateObject("Microsoft.XMLDOM")
xml.async = False
xml.setProperty "ServerHTTPRequest", True
xml.load (url)
Set obj = xml.getElementsByTagName("Article")
For Each Item In obj
Response.Write "Test"
Next


I don't see the "Test" output from this script. For other urls it works fine.
Can anyone help me with this?

The xml file looks like this:
<?xml version="1.0" encoding="utf-8" ?>
- <ROOT>
<COMMAND>Command</COMMAND>
<TIME>Time</TIME>
- <Article>
<Article_Id>651</Article_Id>
<Article_Title>Title</Article_Title>
<Article_Head>Description</Article_Head>
<Article_Link>Link</Article_Link>
<Article_PicName>Picture Name</Article_PicName>
<Article_Date>Date</Article_Date>
</Article>
</ROOT>


Thanks!

Alex Vincent
03-05-2007, 10:05 PM
What language is your script written in? Looks like BASIC.

BarrMan
03-05-2007, 10:19 PM
It's in ASP.

david_kw
03-05-2007, 11:05 PM
Your code worked fine for me. The only thing I had to change was the url on my local machine.

url = "http://localhost/junque/test.xml"

david_kw

BarrMan
03-06-2007, 01:14 PM
Maybe it has something to do with the extenstion?

david_kw
03-06-2007, 04:23 PM
Which extension?

BarrMan
03-06-2007, 04:34 PM
Oh, I'm sorry, I forgot that I didn't post the url.
The extention for the file is ashx.
Thanks.

david_kw
03-06-2007, 09:58 PM
I wouldn't think that would make a difference. You could try renaming the xml file on your side to see I suppose. Unless the header content-type isn't "text/xml"? Even then I'd think it would work although I've never tested it.

david_kw

david_kw
03-06-2007, 10:10 PM
Well I tried renaming my test.xml to test.xmr (random extension) and it still worked fine so I don't think it is JUST the extension. As I recall ASHX is a special extension for ASP. I assume you have browsed to the XML file from a browser and seen that it is serving up correctly? Also you might want to check the response header to see what it is giving.

david_kw

BarrMan
03-07-2007, 12:33 PM
How can I check the response header?

david_kw
03-07-2007, 03:20 PM
A couple ways. The easiest in my opinion is to get FireFox 2 with the Web Developer extension. Then just use the Web Developer menu to choose

Information:View Response Headers

I highly recommend downloading it if you aren't already using it. That and the FireBug extension are the ones I'm constantly using when doing web work.

http://www.mozilla.com/en-US/firefox/
https://addons.mozilla.org/firefox/60/
https://addons.mozilla.org/firefox/1843/

david_kw

BarrMan
03-07-2007, 04:44 PM
Thanks, I solved the problem already :).
I tried using another way:
Set root = xml.documentElement
For i = 2 To (root.childNodes.length - 1)
Response.Write "Hello"
Next