I am trying to read in an XML file into our VB6 app. I have gone through lots of code trying to get the "modifiers" for each "item" in the list, but can only retrieve them all at the same time. The problem seems to be they are all named the same! Any help would be greatly appreciated! - KC
Here is the XML :
<?xml version="1.0" encoding="ISO-8859-1"?> <GetNewOrdersResponse> <ResultCode>0</ResultCode> <Message>Ok</Message> <LocationID>436</LocationID> <StoreTimeGMT>2015-11-27 05:13:38</StoreTimeGMT> <TotalRecords>1</TotalRecords> <Tickets> <ticket> <order_id>5278</order_id> <type>TAKEOUT</type> <comments></comments> <customer> <customer_id></customer_id> <phone_id></phone_id> <firstname>Kyle</firstname> <lastname>Cross</lastname> <email>crosskg62@gmail.com</email> <phone>4438786137</phone> </customer> <created_timestamp>2015-11-26 23:19:47</created_timestamp> <requested_timestamp>2015-11-27 17:00:00</requested_timestamp> <items> <item id="21845" pos_id="5702"> <name>Cheese Pizza</name> <size>12"</size> <quantity>1</quantity> <price>8.95</price> <comments></comments> <modifiers> <modifier id="44347" pos_id="3252"> <name>Thick</name> <price>0.00</price> <quantity>1</quantity> </modifier> <modifier id="44349" pos_id="6000"> <name>Cheddar Cheese</name> <price>0.00</price> <quantity>whole_extra</quantity> </modifier> <modifier id="44350" pos_id="6003"> <name>Green Olives</name> <price>0.50</price> <quantity>left</quantity> </modifier> <modifier id="44351" pos_id="6005"> <name>Black Olives</name> <price>0.50</price> <quantity>right</quantity> </modifier> <modifier id="44353" pos_id="6009"> <name>Tomatoes</name> <price>1.00</price> <quantity>whole</quantity> </modifier> <modifier id="44355" pos_id="6013"> <name>Pineapple</name> <price>0.50</price> <quantity>right</quantity> </modifier> </modifiers> </item> <item id="21782" pos_id="5001"> <name>Big Burger</name> <size></size> <quantity>3</quantity> <price>8.95</price> <comments></comments> <modifiers> <modifier id="44287" pos_id="3044"> <name>Well</name> <price>0.00</price> <quantity>1</quantity> </modifier> <modifier id="44306" pos_id="5100"> <name>Cole Slaw</name> <price>0.00</price> <quantity>1</quantity> </modifier> </modifiers> </item> <item id="21805" pos_id="4700"> <name>Fried Chicken Salad</name> <size></size> <quantity>1</quantity> <price>10.95</price> <comments></comments> <modifiers> <modifier id="44318" pos_id="3030"> <name>Blue Cheese</name> <price>0.00</price> <quantity>1</quantity> </modifier> </modifiers> </item> </items> <subtotal>49.25</subtotal> <tax>3.45</tax> <total>52.70</total> <PaymentType>CASH</PaymentType> <PaymentStatus>UNPAID</PaymentStatus> </ticket> </Tickets>
Here is the code:
Dim xmlDoc As DOMDocument Dim objNodeList As IXMLDOMNodeList Dim objNodeList2 As IXMLDOMNodeList Dim objProductNode As IXMLDOMNode Dim objQuantityNode As IXMLDOMNode Dim objNode As IXMLDOMNode Dim objNode2 As IXMLDOMNode Dim XMLurl As String
Dim strRet As String
Set xmlDoc = New DOMDocument XMLurl = "c:\kyle.xml" xmlDoc.async = False If xmlDoc.Load(XMLurl) = False Then MsgBox ("XML LOAD ERROR") Else i = 0 Set objNodeList = xmlDoc.selectNodes("//items") For Each objNode In objNodeList mPrice = objNode.selectSingleNode("//price").Text mPrice = objNode.selectSingleNode("//price").Text mQty = objNode.selectSingleNode("//quantity").Text mQty = objNode.selectSingleNode("//size").Text Next 'objNode ' get the modifiers for that node Set objNodeList2 = xmlDoc.selectNodes("//Modifier") For Each objNode2 In objNodeList2 mName = xmlDoc.selectSingleNode("//name").Text mPrice = xmlDoc.selectSingleNode("//price").Text mQty = xmlDoc.selectSingleNode("//quantity").Text Next objNode2 End If
No comments:
Post a Comment