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
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
Sorry, needs to have the rest of the code to go with it.
Carrzkiss
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%>
ASKER
Carrzkiss
Thanks for that.
It is now clear with your help, that the problem lies with:
Set books = objXML.getElementsByTagNam e("book")
For i = 0 to (books.Length-1)
books.length returns 0
Any ideas?
Thanks
Thanks for that.
It is now clear with your help, that the problem lies with:
Set books = objXML.getElementsByTagNam
For i = 0 to (books.Length-1)
books.length returns 0
Any ideas?
Thanks
ASKER
More info:
I am trying to read the child elements, of which there are several.
Thanks
I am trying to read the child elements, of which there are several.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
neeraj523:
Awesome.
I tried to do that, but for some weird reason, it would not work for me.
But it did for you.
Carrzkiss
Awesome.
I tried to do that, but for some weird reason, it would not work for me.
But it did for you.
Carrzkiss
ASKER
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....
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.
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
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("Micro soft.XMLDO M")
instead of
Set objXML = Server.CreateObject("MSXML 2.DOMDocum ent")
which allows xml parsing by pulling xml from remote server.
Am i right ?
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("Micro
instead of
Set objXML = Server.CreateObject("MSXML
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
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..
This does
But not sure that it gives you the results that you want??
Open in new window