Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing XML a little help needed please.

Status
Not open for further replies.

uczmeg

MIS
Mar 7, 2001
61
GB
Hi,

I've done very little XML with VB6 and when I have, the file format was somewhat different to the file I now need to process.

The file looks like this:

<os>
<o c="A1D001">
<i c="BOARD001" q="1" />
<i c="BOOKS002" q="2" />
</o>
<o c="ABS001">
<i c="CALC001" q="3" />
<i c="CAS001" q="4" />
</o>
</os>

Where o is an order and c is the customer code.

The the items are i and c is the item code and q is the quantity.

I need to pull out the customer code for each order and the following item codes and quantites.

I know the following code will loop through the orders. But I don't know how to actually pull out the customer codes or how to nest a loop within this to pull out the items:

Dim oDom As New DOMDocument
Dim oOrders As IXMLDOMNodeList
Dim oOrder As IXMLDOMNode

With oDom
If .Load(sXML) Then
If Not oDom.documentElement Is Nothing Then
Set oOrders = oDom.selectNodes("//os/*")
For Each oOrder In oOrders
'get customer code
'loop through items getting code/qty
Next oOrder
End If
End If
End With

Any help greatly appreciated!

Cheers
Marc
 
Sorted it myself:

Set oOrders = oDom.selectNodes("//os/*")
For Each oOrder In oOrders
sCust = oOrder.Attributes(0).nodeValue
Set oItems = oOrder.selectNodes("*")
For Each oItem In oItems
sCode = oItem.Attributes(0).nodeValue
sQty = Val(oItem.Attributes(1).nodeValue)
Next
Next oOrder
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top