Hi all.
I'm struggling to come to grips with parsing an XML file because I need to implement a very simple example of the Namecheap API.
The API requires me to submit a very long URL (see the variable 'filepath' in my example code further down). When I drop the URL straight into Firefox it returns the following:
<ApiResponse Status="OK">
<Errors/>
<RequestedCommand>namecheap.domains.check</RequestedCommand>
<CommandResponse Type="namecheap.domains.check">
<DomainCheckResult Domain="sdrgdsfgjh.com" Available="true"/>
</CommandResponse>
<Server>WIN-R1-WEB2</Server>
<GMTTimeDifference>--4:00</GMTTimeDifference>
<ExecutionTime>0.719</ExecutionTime>
</ApiResponse>
And here also is the page source for that display:
<?xml version="1.0" encoding="utf-8"?>
<ApiResponse Status="OK" xmlns="http://api.namecheap.com/xml.response">
<Errors />
<RequestedCommand>namecheap.domains.check</RequestedCommand>
<CommandResponse Type="namecheap.domains.check">
<DomainCheckResult Domain="sdrgdsfgjh.com" Available="true" />
</CommandResponse>
<Server>WIN-R1-WEB2</Server>
<GMTTimeDifference>--4:00</GMTTimeDifference>
<ExecutionTime>5.469</ExecutionTime>
</ApiResponse>
All I need to do is parse that output with server-side code (I'm using Asp) to display the fact that "sdrgdsfgjh.com" is or isn't available for registration. After trying a number of variations, I've finally come up with some code (modified from someone else's example) that executes without errors -- but neither does it give me the required output. Here's my code:
<%
Dim objXML, objItemList, objItem, filepath
filepath = "https://api.namecheap.com/xml.response?"&_
"&ApiUser=billybunter"&_ ' This is fake
"&ApiKey=asdasdgdsgdg"&_ ' This is fake
"&UserName=billybunter"&_ ' This is fake
"&Command=namecheap.domains.check"&_ ' This is REAL
"&ClientIp=192.168.1.100"&_ ' This is fake
"&DomainList=sdrgdsfgjh.com" ' This is fake
Set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.async = False
objXML.setProperty "ServerHTTPRequest", True
objXML.Load(filepath)
If objXML.parseError.errorCode <> 0 Then
Response.Write "Error: " & objXML.parseError.reason
Response.Write "Line : " & objXML.parseError.line & vbCrLf
Response.Write "Text : " & Server.HTMLEncode(objXML.parseError.srcText) & vbCrLf
End If
Set objItemList = objXML.getElementsByTagName("DomainCheckResult")
For Each objItem In objItemList
Response.Write("Item 1 : " & objItem.text & "<br />")
Response.Write("Item 2 : " & objItem.text & "<br />")
Response.Write("Item 3 : " & objItem.text & "<br />")
Next
Set objXML = Nothing
Set objItemList = Nothing
%>
I'm reasonably sure I know where I'm going wrong, I just don't know what should be in the "Set objItemList = " line or the For/Next loop. What's shown above is just the most recent of many tries.
Any help much appreciated.