XMLElementDepth (QTP, TestComplete, VBScript)
Parent page: Service Functions – MSXMLDOM (QTP, TestComplete, VBScript)
Description
Locate XML node depth within the hierarchy. Valid argument: an XML element node (NODE_ELEMENT type).
Implementation
Public Function XMLElementDepth(ByRef objXMLElement) Dim intDepth Dim objXMLNode If objXMLElement is Nothing Then XMLElementDepth = -1 Exit Function End If 'NODE_DOCUMENT(9) If objXMLElement.NodeType = 9 Then XMLElementDepth = 0 Exit Function End If 'NODE_ELEMENT(1) If objXMLElement.NodeType <> 1 Then XMLElementDepth = -1 Exit Function End If intDepth = 0 Set objXMLNode = objXMLElement Do While True Set objXMLNode = objXMLNode.parentNode intDepth = intDepth + 1 If objXMLNode.NodeType = 9 Then Exit Do End If Loop XMLElementDepth = intDepth End Function