I need to parse a xmlobject and extract from the nodes two values I am able to get two values from those trees. I am stuck on how to traverse down into the node in the loop to grab a value that then will determine if I can grab a second value.
This is in VBS and is being used as an extension in an already functioning program. Have been looking up here and Microsoft documentation but am having trouble getting good information from them for VBS in particular.
Example XML
<Detail>
<StandardLine>
<Stan>
<Type>A</Type>
<Code>1234</Code>
<Value>sdg</Value>
</Stan>
</StandardLine>
<StandardLine>
<Stan>
<Type>C</Type>
<Code>122234</Code>
<Value>sdsdgg</Value>
<Cate>Thiere</Cate>
</Stan>
</StandardLine>
<StandardLine>
<Stan>
<Type>1</Type>
<Code>7336</Code>
<Value>this one</Value>
<Stone>diamond</Stone>
</Stan>
</StandardLine>
</Detail>
Dim xmlDoc, nodes, strQuery, objNode
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.Async = "False"
'This is inputing the xml as a string from a previous bit of code
xmlDoc.loadXML(XMLOut)
strQuery = "//Detail/StandardLine"
Set nodes = xmlDoc.documentElement.selectNodes(strQuery)
'Check to see if this xmlDoc has any of the desired SL nodes
If nodes.length = 0 Then
msgbox "There are no SLine nodes",,"The checker"
exit function
End If
'Will only get this far if there is a SLine node
msgbox "Before Nodes" & vbCrLf & nodes.length,,"Pre loop"
' Will go through each SLinenodes
For Each objNode in nodes
msgbox "I am in the loop!",,"The box...in the loop"
'Here down is what I want to do but am not able to get it to work
'Need to to process the SLine node
Type = objNode.documentElement.selectSingleNode("//Stan/Type").text
If Type = 1 Then
Code = objNode.documentElement.selectSingleNode("//Stan/Code").text
End if
'Will be functions here later to use the variable Code
msgbox "Number is: " & Code,,"Thereas the number?"
Next
msgbox "After Nodes",,"Post loop"
I want to extract from the above XML the value in the element if the value of the element is 1.
Edit: fixed a misplaced '/' in the example xml