Note that there are some explanatory texts on larger screens.

plurals
  1. POExcel VBA XML Navigation
    primarykey
    data
    text
    <p>I'm having some issues extracting values from some XML using VBA in Excel 2007. Here is a sample of what the data looks like:</p> <pre><code>&lt;work_order xmlns="http://www.sample.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:schemaLocation="http://www.sample.com" id=""&gt; &lt;link rel="self" type="application/xml" href="http://www.sample.com"/&gt; &lt;work_order_info&gt;...&lt;/work_order_info&gt; &lt;entry_info&gt;...&lt;/entry_info&gt; &lt;posting_info&gt;...&lt;/posting_info&gt; &lt;instructions&gt;...&lt;/instructions&gt; &lt;address_info&gt;...&lt;/address_info&gt; &lt;crew_time&gt; &lt;confirm_date&gt;04 Dec 2013&lt;/confirm_date&gt; &lt;minutes_required&gt;100&lt;/minutes_required&gt; &lt;/crew_time&gt; &lt;wo_products&gt; &lt;wo_product&gt; &lt;product_description&gt;pants&lt;/product_description&gt; &lt;/wo_product&gt; &lt;wo_product&gt; &lt;product_description&gt;shirt&lt;/product_description&gt; &lt;/wo_product&gt; &lt;wo_product&gt; &lt;product_description&gt;shoes&lt;/product_description&gt; &lt;/wo_product&gt; &lt;wo_product&gt; &lt;product_description&gt;hat&lt;/product_description&gt; &lt;/wo_product&gt; &lt;wo_product&gt; &lt;product_description&gt;DPSB1&lt;/product_description&gt; &lt;/wo_product&gt; &lt;/wo_products&gt; </code></pre> <p></p> <p>What I need to do is loop through each of the wo_product nodes and get the product_description. What I have so far is:</p> <pre><code>Dim nodeList As IXMLDOMNodeList Dim node As IXMLDOMNode Dim oXMLDoc As MSXML2.DOMDocument Set oXMLDoc = New MSXML2.DOMDocument oXMLDoc.async = False oXMLDoc.Load "http://www.sample.com" Set nodeList = oXMLDoc.SelectNodes("/work_order/wo_products/wo_product") For Each node In nodeList Dim description As String description = node.SelectSingleNode("//product_description").Text MsgBox (description) Next node </code></pre> <p>It loops through 5 times, but the message box says "pants" every time. Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload