Link to home
Start Free TrialLog in
Avatar of savillek
savillek

asked on

Reading XML feed with ASP

Can some tell me why this code is not returning any nodes, when I know there is data in the file.

Your help would be much appreciates


Set objXML = Server.CreateObject("Microsoft.XMLDOM")
 
objXML.async = False
 
objXML.Load ("http://www.flower-gardening-made-easy.com/Flower-gardening.xml")
 
If objXML.parseError.errorCode = 0 Then
     Response.Write "Error Parsing XML"
     Response.Write  "Rason :" & objXML.parseError.reason & "Error Line: " & objXML.parseError.line
End If
 
Set books = objXML.getElementsByTagName("book")
 
For i = 0 to (books.Length-1)
    Response.Write "Name: " & books.item(i).childNodes(0).text  & "<br/>"
    Response.Write "Description: " & books.item(i).childNodes(1).text & "<br/>"
    Response.Write "Author: " & books.item(i).childNodes(2).text & "<br/>"
Next

Open in new window

Avatar of Wayne Barron
Wayne Barron
Flag of United States of America image

not really sure why it will not retrieve the results.
This does

But not sure that it gives you the results that you want??

 
 
<%Response.Write objXML.getElementsByTagName("title").item(0).Text%><br/>
<%Response.Write objXML.getElementsByTagName("description").item(0).Text%>

Open in new window

Sorry, needs to have the rest of the code to go with it.

Carrzkiss
<%
Dim URL, count, objXML, i, counter
URL = "http://www.flower-gardening-made-easy.com/Flower-gardening.xml"
 
Set objXML = Server.CreateObject("Microsoft.XMLDOM")
 
'Using the "server-safe" ServerXMLHTTP component to load the document to the server.
'ServerXMLHTTP only supports synchronous loading;
objXML.setProperty "ServerHTTPRequest", True
 
objXML.async =  False
objXML.Load(URL) 
If objXML.parseError.errorCode <> 0  Then
	Response.Write(objXML.parseError.reason)
	Response.Write(objXML.parseError.errorCode)
End If
%>
Name: <%Response.Write objXML.getElementsByTagName("title").item(0).Text%><br/>
Description: <%Response.Write objXML.getElementsByTagName("description").item(0).Text%>

Open in new window

Avatar of savillek
savillek

ASKER

Carrzkiss

Thanks for that.

It is now clear with your help, that the problem lies with:

Set books = objXML.getElementsByTagName("book")
For i = 0 to (books.Length-1)

books.length returns 0

Any ideas?

Thanks
More info:

I am trying to read the child elements, of which there are several.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of neeraj523
neeraj523
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
neeraj523:
Awesome.
I tried to do that, but for some weird reason, it would not work for me.
But it did for you.

Carrzkiss
Many thanks for your help. Works like a charm.
that is pretty bad, considering that "neeraj523"
Used your non-working code and added my working code into it.
To give you your results.

This should have been a split....

@carrzkiss.. wondering on your so called 'my working code'.. better if you compare carefully your provided solution with mine before blaming copying..

I did

You just added in his code to the bottom to make it work.
url = "http://www.flower-gardening-made-easy.com/Flower-gardening.xml"       same
 
Set objXML = Server.CreateObject("MSXML2.DOMDocument")       same
objXML.async = False       same
objXML.setProperty "ServerHTTPRequest", True       same
objXML.Load(url)       same

Open in new window

Dear carrzkiss

Well.. i don't think this is a good idea to argue on this.. but just for clarification, you used in your code

Set objXML = Server.CreateObject("Microsoft.XMLDOM")

instead of

Set objXML = Server.CreateObject("MSXML2.DOMDocument")

which allows xml parsing by pulling xml from remote server.

Am i right ?
your right.
Sorry, read that "1" line to fast.
The other "4" are the same.
But regardless.
You know just as well as I do that this should have been a split.

Carrzkiss

i dont mind with Split.. but dear carrzkiss, the question here was only about to use the correct object ie 'DOMDocument' instead of 'XMLDOM' which u didnt indicated. The output of your solution might not be different from the output what savillek already getting..