How to get node value of XML using function getElementsByTagName on VBScript?
I'm utilizing version 11.0.644 of TestComplete.
XML:
<tag1>
<tag2>
<mod>Test </mod>
</tag2>
</tag1>
I'm using this code for obtain the node value from XML:
Sub XMLTest
Set XMLTestReader = Sys.OleObject("Msxml2.DOMDocument.6.0")
XMLTestReader.async = false
XMLTestReader.load(XML.XML_Teste.Document)
Set nodeText = XMLTestReader.getElementsByTagName("mod").item(0).childNodes.item(0).nodeValue
BuiltIn.ShowMessage(nodeText)
End Sub
The XML is present in Stores/XML/XML_Teste.
This code returns error.
How to obtain the correct node value?
Okay, this line of your code:
XMLTestReader.load(XML.XML_Teste.Document)
The load method of MSXML takes a filepath to an XML file as the argument. XML.XML_Teste.Document will return a DOM object that represents the XML, not the filepath. If you want you can pass in the actual file path to the XML file, but Document property of an XML checkpoint already return a DOM object like what you want. So your code could just be like this:
Sub XMLTest Set nodeText = XML.XML_Teste.Document.getElementsByTagName("mod").item(0).text BuiltIn.ShowMessage(nodeText)
I use python so hopefully that's all the correct syntax.