12 years ago
Reading sub child of a sub child in an xml file
Hi..
I need to read the values of a child/sub node of a child node. Pls see the xml file attached.. There may be multiple sub nodes of the same name, i need all the values read and returned in an array..
I was using this code to read a child node -
Function GetXMLChildNodeValue(XMLFile,NodeName,SubNodeName)
Dim RtnValue
Dim XMLDocObj
Dim ChildNodesObject
Dim ChildNode
Dim Reason,ChildSubNodes
LogFolder = Log.AppendFolder("Getting Node value for SubNodeName :" & SubNodeName & _
" in XML file: " & XMLFile)
RtnValue = TC_FAIL
Set XMLDocObj = CreateObject("Microsoft.XMLDOM")
XMLDocObj.async = False
XMLDocObj.Load(XMLFile)
If XMLDocObj.parseError.errorCode = 0 Then
If XMLDocObj.documentElement.hasChildNodes then
Set ChildNodesObject = XMLDocObj.documentElement.childNodes
For Each ChildNode In ChildNodesObject
If ChildNode.nodeName = NodeName then
If ChildNode.hasChildNodes then
For each ChildSubNodes in ChildNode.childNodes
If ChildSubNodes.nodeName = SubNodeName then
RtnValue = ChildSubNodes.Text
Log.Message("Value of the " & SubNodeName & " Node is " & RtnValue)
End If
Next
Else
Log.Message("There are no sub child nodes")
End If
End If
Next
Else
Log.Message("There are no child nodes")
End If
Else
Log.Error("Cannot parse the xml document;Check whether the file extension is correct")
End If
GetXMLChildNodeValue = RtnValue
Log.PopLogFolder()
End Function
This reads all child node values.. I can modify it for them to be returned in an array.
Can this be extended to read sub child node values too? Like for say "Line width" in the attached file?
Also how can i read the values for <size> under <Label Font>.. that would be a child node's child node's child...
I need to read the values of a child/sub node of a child node. Pls see the xml file attached.. There may be multiple sub nodes of the same name, i need all the values read and returned in an array..
I was using this code to read a child node -
Function GetXMLChildNodeValue(XMLFile,NodeName,SubNodeName)
Dim RtnValue
Dim XMLDocObj
Dim ChildNodesObject
Dim ChildNode
Dim Reason,ChildSubNodes
LogFolder = Log.AppendFolder("Getting Node value for SubNodeName :" & SubNodeName & _
" in XML file: " & XMLFile)
RtnValue = TC_FAIL
Set XMLDocObj = CreateObject("Microsoft.XMLDOM")
XMLDocObj.async = False
XMLDocObj.Load(XMLFile)
If XMLDocObj.parseError.errorCode = 0 Then
If XMLDocObj.documentElement.hasChildNodes then
Set ChildNodesObject = XMLDocObj.documentElement.childNodes
For Each ChildNode In ChildNodesObject
If ChildNode.nodeName = NodeName then
If ChildNode.hasChildNodes then
For each ChildSubNodes in ChildNode.childNodes
If ChildSubNodes.nodeName = SubNodeName then
RtnValue = ChildSubNodes.Text
Log.Message("Value of the " & SubNodeName & " Node is " & RtnValue)
End If
Next
Else
Log.Message("There are no sub child nodes")
End If
End If
Next
Else
Log.Message("There are no child nodes")
End If
Else
Log.Error("Cannot parse the xml document;Check whether the file extension is correct")
End If
GetXMLChildNodeValue = RtnValue
Log.PopLogFolder()
End Function
This reads all child node values.. I can modify it for them to be returned in an array.
Can this be extended to read sub child node values too? Like for say "Line width" in the attached file?
Also how can i read the values for <size> under <Label Font>.. that would be a child node's child node's child...