Excel VBA XML导航

Excel VBA XML导航,xml,vba,excel,Xml,Vba,Excel,我在Excel2007中使用VBA从一些XML中提取值时遇到一些问题。以下是数据的示例: <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=""> <link

我在Excel2007中使用VBA从一些XML中提取值时遇到一些问题。以下是数据的示例:

<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="">
<link rel="self" type="application/xml" href="http://www.sample.com"/>
<work_order_info>...</work_order_info>
<entry_info>...</entry_info>
<posting_info>...</posting_info>
<instructions>...</instructions>
<address_info>...</address_info>
<crew_time>
    <confirm_date>04 Dec 2013</confirm_date>
    <minutes_required>100</minutes_required>
</crew_time>
<wo_products>
    <wo_product>
        <product_description>pants</product_description>
    </wo_product>
    <wo_product>
        <product_description>shirt</product_description>
    </wo_product>
    <wo_product>
        <product_description>shoes</product_description>
    </wo_product>
    <wo_product>
        <product_description>hat</product_description>
    </wo_product>
    <wo_product>
        <product_description>DPSB1</product_description>
    </wo_product>
</wo_products>

它循环了5次,但消息框每次都显示“裤子”。有什么想法吗?

使用
description=node。选择singlenode(“产品描述”)。Text

我发誓我以前试过,但没有用。我想//告诉它从你现在的位置继续搜索?类似于./in直接引用您所在的终端?如果需要,您可以尝试
description=node。选择singlenode(“./product\u description”)。Text
<代码>/错误。
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