DasSaffe
DasSaffe

Reputation: 2198

Read XML with classic ASP (DACK)

I followed this question here: Reading xml data using classic ASP to begin with, but I'm encountering an error and I don't know why that is. This might be due to this DACK-standard the XML file is formatted or maybe related to not being able to load the file.

I'm always ending up with:

Object required: 'objXMLDoc.documentElement'

My function looks like this so far

public function extractValTicketNumber(xmlResponse)
    Set objXMLDoc = Server.CreateObject("MSXML2.DOMDocument.3.0")
    objXMLDoc.async = false
    objXMLDoc.load Server.MapPath("/DOCK.xml")

    Dim xmlProduct
    For Each xmlProduct In objXMLDoc.documentElement.selectNodes("ns1:mt_DG_DACK_V3")
        Dim TicketNumber : TicketNumber = xmlProduct.selectSingleNode("ns1:ticketNo").text 
    Next
    response.write("Ticket Nummer: " & Ticketnummer)

end function

And my XML-File is like this:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<ns1:mt_DG_DACK_V3 xmlns:ns1="urn:dg:dack">
    <ns1:transactionID>012345678900000001</ns1:transactionID>
    <ns1:externalTicketID>IN-6543210</ns1:externalTicketID>
    <ns1:ticketNo>IN-0123456</ns1:ticketNo>
    <ns1:returnMessage>Message successfully received and validated</ns1:returnMessage>
    <ns1:returnCode>0</ns1:returnCode>
</ns1:mt_DG_DACK_V3>

The output of Server.MapPath("/DACK.xml") is the correct one, so the file should be loaded. D:\TestIntranet\wwwroot\DOCK.xml

enter image description here

Can I test this somehow? I'm not too deep into classic ASP.

I tried to change the parent-node to something without prefix, testNode but still the same error, so I guess it isn't related to that.

Update:

I just tried to load a string as argument instead of a file, but the error still remains:

Set objXMLDoc = Server.CreateObject("MSXML2.DOMDocument.3.0")
dim xmlTestString : xmlTestString = "<Product><ProductCode>abc</ProductCode><ProductName>Name</ProductName></Product>"
objXMLDoc.async = False
objXMLDoc.load(xmlTestString)

Upvotes: 1

Views: 345

Answers (1)

user692942
user692942

Reputation: 16671

If you are confident that Server.MapPath() contains a valid path to the XML file you next thing to check that Load() is happy parsing the file.

objXMLDoc.load Server.MapPath("/DOCK.xml")
If objXMLDoc.parseError = 0 Then
  'Document loaded successfully without errors
Else
  'Document cannot be parsed
  Call Response.Write(objXMLDoc.parseError.reason)
End If

Upvotes: 0

Related Questions