Home > OS >  getElementsByTagName returning "Wrong number of arguments or invalid property assignment"
getElementsByTagName returning "Wrong number of arguments or invalid property assignment"

Time:12-28

I am working with a vendor-supplied API that returns this XML when I call it.

<RESPONSE>
    <VALID>true</VALID>
    <MESSAGE></MESSAGE>
    <DATA>
        <WORK>
            <ROW type="object" >
                <brief_desc>Check plate</brief_desc>
                <compid>1354</compid>
                <comp_desc>Spitfire #2</comp_desc>
                <initials></initials>
                <sch_date>2019-10-01</sch_date>
                <wo>43351</wo>
                <workstatus>O</workstatus>
                <work_desc>Check plate for flatness</work_desc>
            </ROW>
            <ROW type="object" >
                <brief_desc>Check wheel</brief_desc>
                <compid>1354</compid>
                <comp_desc>Spitfire #1</comp_desc>
                <initials></initials>
                <sch_date>2019-10-08</sch_date>
                <wo>43685</wo>
                <workstatus>O</workstatus>
                <work_desc>Check wheel for roundness</work_desc>
            </ROW>
        </WORK>
    </DATA>
</RESPONSE>

I call this from another vendor-supplied HMI software, that only supports VBscript. I can get individual values like this, using the Microsoft.XMLDOM object:

xmlDoc.documentElement.selectSingleNode("//VALID").text

However, when I try to get a collection of the "WORK" node, like this...

objNodeList = xmlDoc.getElementsByTagName("DATA")

...I get an error stating "Wrong number of arguments or invalid property assignment". The "DATA" element is all caps, so I think I have the name correct. I have researched this quite a bit, but can't seem to find someone with the exact same issue. I would appreciate any suggestions anyone might have. Thank you!

CodePudding user response:

I would suggest to use a different method, i.e. selectNodes().

objNodeList = xmlDoc.selectNodes("/RESPONSE/DATA")

or

objNodeList = xmlDoc.selectNodes("/RESPONSE/DATA/WORK/ROW")

CodePudding user response:

The issue appears to be with the code that you haven't yet shared. The following code works fine with your XML file. Note that you have the option of using selectNodes or getElementsByTagName.

Set xmlDoc =  CreateObject("Microsoft.XMLDOM")
xmlDoc.Load ".\Test.xml"

WScript.echo "Using selectNodes..."

Set xmlNodes = xmlDoc.documentElement.selectNodes("DATA/WORK")

For Each xmlNode in xmlNodes
  WScript.echo xmlNode.text
Next

WScript.echo "Using getElementsByTagName..."

Set xmlNodes = xmlDoc.getElementsByTagName("DATA/WORK")

For Each xmlNode in xmlNodes
  WScript.echo xmlNode.text
Next
  • Related