1

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)
DasSaffe
  • 2,080
  • 1
  • 28
  • 67
  • 1
    Why do you call `documentElemnt` on the `xmlProduct`? – choroba Apr 08 '20 at 08:11
  • Could be it's not finding the `Server.MapPath()` but you said you've checked that. Have you checked the `parseError.errorCode`? – user692942 Apr 08 '20 at 08:12
  • @choroba I'm leaning heavily towards this answer here: https://stackoverflow.com/a/11530772/3372043 I tried to access the element directly, but there is still the same error. – DasSaffe Apr 08 '20 at 08:14
  • @choroba my bad, removed that and updated the code-snippet. The error still remains though. It seems like the problem lies within the For Each or the object itself – DasSaffe Apr 08 '20 at 08:23
  • I think the declared server object is not created. Properbly the plugin cannot create an object. Have you tried it with a simple classic xml file? – Reporter Apr 08 '20 at 08:26
  • @Reporter doesn't work with a simple xml-file as well (same example as from the linked answer above). Same error – DasSaffe Apr 08 '20 at 08:31
  • Uhm https://www.tek-tips.com/viewthread.cfm?qid=1656952 shows a different syntax for the load function. There are round brackets those wrap the file path. – Reporter Apr 08 '20 at 08:45
  • @Reporter no. See [Cannot use parentheses when calling a Sub](https://ericlippert.com/2003/09/15/what-do-you-mean-cannot-use-parentheses/) to understand why. – user692942 Apr 08 '20 at 08:57

1 Answers1

0

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
user692942
  • 16,398
  • 7
  • 76
  • 175
  • interesting, it says: `The system cannot locate the object specified`. Does this refer to the file, or is there a problem with that object itself? I tried it with the Server.MapPath() and simply with `DOCK.xml`, since they are both in the same directory on the server – DasSaffe Apr 08 '20 at 08:35
  • @DasSaffe means that it's not locating the XML file. If you `Response.Write Server.MapPath("/DOCK.xml")` what is the output? – user692942 Apr 08 '20 at 08:52
  • I edited the question a few minutes ago, with the output + screenshot of the file with its location – DasSaffe Apr 08 '20 at 08:54
  • @DasSaffe this might be relevant - [MSXML3.dll 80072efd and 800c0005 errors executing ServerXMLHTTP.send in classic ASP on Windows 7](https://stackoverflow.com/a/4368725). Could be permission related if the path is correct. – user692942 Apr 08 '20 at 08:54
  • I just tried ith with a simple XML-String as load-param, but same error. I'll update the question. I have the feeling that this is somewhat related to the `CreateObject`-thing. – DasSaffe Apr 08 '20 at 09:00
  • You can't pass XML to `Load()` like that, it will give you the `The filename, directory name, or volume label syntax is incorrect.` error. You need to use the [`LoadXML()` method](https://learn.microsoft.com/en-us/previous-versions/windows/desktop/ms754585(v%3Dvs.85)). – user692942 Apr 08 '20 at 09:06
  • 1
    okay, seems good. That at least gets rid off the error. We can now be sure it is related to the file it is trying to locate. I'll have a shot and the link u suggested with the pools. Thanks so far! – DasSaffe Apr 08 '20 at 09:08