0

I have the following xml result from this link - https://api.eveonline.com/eve/CharacterID.xml.aspx?names=BorisKarlov

<eveapi version="2">
<currentTime>2013-01-16 18:57:38</currentTime>
<result>
<rowset name="characters" key="characterID" columns="name,characterID">
<row name="BorisKarlov" characterID="315363291"/>
</rowset>
</result>
<cachedUntil>2013-02-16 18:57:38</cachedUntil>
</eveapi>

and I am trying to extract the characterID into asp. I am using the following code,

Set oXML = Server.CreateObject("Msxml2.DOMDocument.6.0")
oXML.LoadXML("https://api.eveonline.com/eve/CharacterID.xml.aspx?names=BorisKarlov")

Set oRoot = oXML.selectSingleNode("//result")

For Each oNode In oRoot.childNodes
  response.Write oNode.Attributes.getNamedItem("characterID").Text
Next 

Set oXML = Nothing 

All i keep getting is the following error:

Microsoft VBScript runtime error '800a01a8'

Object required: 'oRoot'

.............

I can only assume that Set oRoot = oXML.selectSingleNode("//result") is not actually generating any data and therefore throwing up the error in the next line.

Can anyone please shed some light on my problem?

2
  • Try adding oXML.setProperty "SelectionLanguage", "XPath" Commented Jan 17, 2013 at 4:35
  • thank you for your reply, i've added that line but still getting the Object required: 'oRoot' error Commented Jan 17, 2013 at 18:01

1 Answer 1

1

You have a few problems there.

  1. loadXML() is for loading a block of XML as a string, not fetching from a remote server; for that, you need to use load()
  2. when loading from a server, you need to tell it to use the ServerXMLHTTP component, and set async to false so that it waits until loaded before executing the rest of your script.
  3. when I tried loading that XML, I got an encoding error; you will need to resolve that one way or another
  4. when I loaded the XML directly from a string, it wouldn't parse because there is a script element containing non-XML content; that needs to be contained within a CDATA section
  5. your XPath query is to //result, but you actually need it to be //result/rowset

This code should work once you resolve issues 3 and 4 above:

Set oXML = Server.CreateObject("Msxml2.DOMDocument.6.0")
oXML.async = False
oXML.setProperty "ServerHTTPRequest", true

oXML.Load("https://api.eveonline.com/eve/CharacterID.xml.aspx?names=BorisKarlov")

If oXML.parseError.errorCode <> 0 Then
    Response.Write "<p>XML parse error: " & Server.HTMLEncode(oXML.parseError.reason) & "</p>"
Else
    Set oRoot = oXML.selectSingleNode("//result/rowset")

    If oRoot Is Nothing Then
        response.write "Nothing!"
        response.end
    End If

    For Each oNode In oRoot.childNodes
        response.Write oNode.Attributes.getNamedItem("characterID").Text
    Next
End If

Set oXML = Nothing

Edit: to get around the problem #3, and oddly also #4 (don't know why!), use this snippet to load the XML instead. For some reason, I think the code above isn't handling the gzip compressed stream correctly, but this code below does.

Set oXML = Server.CreateObject("Msxml2.DOMDocument.6.0")
Set xh = Server.CreateObject("Msxml2.ServerXMLHTTP.6.0")
xh.open "GET", "https://api.eveonline.com/eve/CharacterID.xml.aspx?names=BorisKarlov", False
xh.send
xml = xh.responseText
oXML.LoadXML xml
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much for your reply @webaware, I have no way of altering the generated XML pages because they are generated by 3rd party, I just require the info generated, so if I understand you correctly (which I hope I do as I'm kinda noob at XML) I can go no further down this road. Is there a different method to gather the required info from XML?
@BorisKarlov: if this answer fixes your problem, please accept it so that it won't keep showing up on lists of unanswered questions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.