How to Parse XML in ASP?

Please support our ASP advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
Reply

Join Date: Jun 2005
Posts: 54
Reputation: senexom is an unknown quantity at this point 
Solved Threads: 0
senexom's Avatar
senexom senexom is offline Offline
Junior Poster in Training

How to Parse XML in ASP?

 
0
  #1
Aug 8th, 2005
Hey guys,
I'm having a "great" pleasure of parsing XML in my ASP page, except I can't seem to figure it out what I'm doing wrong. I have tried a bunch of stuff and can't seem to read a simple xml doc. here is what my code looks like...
  1. ' Create new XML reader object
  2. Dim xmlDoc
  3. Set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
  4.  
  5. ' Load the specified XML file (returns XML output)
  6. xmlDoc.load("http://somesite.com/api/xml?action=login&login=jon@doe.com&password=foobar")
  7.  
  8. ' Parse XML
  9. if xmlDoc.parseError.errorcode <> 0 then
  10. ' oops error in xml
  11. Response.Write("XML Error...<br>")
  12. else
  13. ' get xml data
  14. Response.Write(xmlDoc.documentElement.childNodes(0).attributes.getNamedItem("code").nodeValue)
  15. end if

my xml looks like this...
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <results>
  3. <status code="value"/>
  4. </results>

and my error is...
Microsoft VBScript runtime error '800a01a8'

Object required: 'documentElement'
This is my first time working with XML in ASP, so it is possible i'm missing something simple, any ideas what's going wrong here?

Thanks
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 54
Reputation: senexom is an unknown quantity at this point 
Solved Threads: 0
senexom's Avatar
senexom senexom is offline Offline
Junior Poster in Training

Re: How to Parse XML in ASP?

 
0
  #2
Aug 9th, 2005
I've figured it out and just in case someone else is forced to use ASP to process XML...

The code above WORKS on an XML document on the server, but if you are like me and you're trying to read XML document from a response stream the following code does the trick...

  1. set xmlDoc = createObject("MSXML2.DOMDocument")
  2.  
  3. xmlDoc.async = False
  4. xmlDoc.setProperty "ServerHTTPRequest", true
  5. xmlDoc.load("http://somesite.com/api/xml?action=login&login=jon@doe.com&password=foobar")
  6.  
  7. response.write xmlDoc.selectSingleNode("//results/status").Attributes.GetNamedItem("code").Text
Cheers!
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 2
Reputation: dude9er is an unknown quantity at this point 
Solved Threads: 0
dude9er dude9er is offline Offline
Newbie Poster

Re: How to Parse XML in ASP?

 
0
  #3
Jun 29th, 2007
I am having to send a form to a 3rd party server, the server will respond with a XML validation and policy number. I need to then parse this XML response with ASP into my own webpage.

The info you have given so far seems to be what I need but I can't get it to work. Can you give more information on what you did to parse the XML, including ASP and XML code samples?

Much appreciated!!!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC