Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42448

How to get nodes and sub nodes of an XML file

$
0
0
I need to get the info from the XML nodes below and its child nodes. I want to get the label, maturity, bid1 and ask1 value from the XML file but when I run my code, it kept looping other value for the same label. Appreciate your help as I'm still new in vb. Thanks

<scpr:label xc:value="TEST 1121">
<scpr:maturity xc:value="SPOT" xc:type="Fields">
<mp:bid1 xc:keyFormat="N">1234</mp:bid1>
<mp:ask1 xc:keyFormat="N">1234</mp:ask1>
<mp:quotation xc:keyFormat="C">PRICE</mp:quotation>
<mp:clo xc:keyFormat="N">5678</mp:clo>
<mp:lst xc:keyFormat="N">5678</mp:lst>
<mp:min xc:keyFormat="N">0</mp:min>
<mp:max xc:keyFormat="N">0</mp:max>
</scpr:maturity>
</scpr:label>
<scpr:label xc:value="TEST 01/26">
<scpr:maturity xc:value="SPOT" xc:type="Fields">
<mp:bid1 xc:keyFormat="N">7890</mp:bid1>
<mp:ask1 xc:keyFormat="N">7890</mp:ask1>
<mp:quotation xc:keyFormat="C">PRICE</mp:quotation>
<mp:clo xc:keyFormat="N">3456</mp:clo>
<mp:lst xc:keyFormat="N">3456</mp:lst>
<mp:min xc:keyFormat="N">0</mp:min>
<mp:max xc:keyFormat="N">0</mp:max>
</scpr:maturity>
</scpr:label>

The code that I'm using is as below.

Dim xmlDoc As DOMDocument
Dim xmlDoc2 As DOMDocument
Dim objNodeList As IXMLDOMNodeList
Dim objNodeList2 As IXMLDOMNodeList
Dim objBid1Node As IXMLDOMNode
Dim objAsk1Node As IXMLDOMNode
Dim objvalueNode As IXMLDOMNode
Dim objtypeNode As IXMLDOMNode
Dim objLabelNode As IXMLDOMNode
Dim objMaturityNode As IXMLDOMNodeList
Dim objNode As IXMLDOMNode
Dim objNode2 As IXMLDOMNode
Dim XMLurl As String
Dim strRet As String

Set xmlDoc = New DOMDocument
XMLurl = "C:\test.xml"

xmlDoc.async = False

If xmlDoc.Load(XMLurl) = False Then
MsgBox ("XML LOAD ERROR")
Else
Set objNodeList = xmlDoc.selectNodes("//scpr:label")
For Each objNode In objNodeList
Set objLabelNode = objNode.selectSingleNode("@xc:value")
Set objMaturityNode = objNode.selectNodes("//scpr:maturity")
For Each objNode2 In objMaturityNode
Set objBid1Node = objNode2.selectSingleNode("mp:bid1")
Set objAsk1Node = objNode2.selectSingleNode("mp:ask1")
strRet = "Label = " & objLabelNode.Text & vbCrLf & _
"Bid1 = " & objBid1Node.Text & vbCrLf & _
"Ask1 = " & objAsk1Node.Text
MsgBox strRet
Next objNode2
Next objNode
End If

Viewing all articles
Browse latest Browse all 42448

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>