首页 > 解决方案 > 用于抓取所有元素的 XML xPath 语法

问题描述

需要从此输出中获取:对于 NameRecomendation:标记所有值并将其存储到组合框。

xml输出:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Body>
    <GetCategorySpecificsResponse xmlns="urn:ebay:apis:eBLBaseComponents">
      <Timestamp>2018-10-29T18:44:11.220Z</Timestamp>
      <Ack>Success</Ack>
      <CorrelationID>xxxxx</CorrelationID>
      <Version>1077</Version>
      <Build>E1077_CORE_API6_18790878_R1</Build>
      <Recommendations>
        <CategoryID>10986</CategoryID>
        <NameRecommendation>
          <Name>Brand</Name>
          <ValidationRules>
            <ValueType>Text</ValueType>
            <MaxValues>1</MaxValues>
            <SelectionMode>FreeText</SelectionMode>
            <VariationSpecifics>Disabled</VariationSpecifics>
          </ValidationRules>
          <ValueRecommendation>
            <Value>Unbranded</Value>
            <ValidationRules />
          </ValueRecommendation>
          <ValueRecommendation>
            <Value>Handmade</Value>
            <ValidationRules />
          </ValueRecommendation>
          <ValueRecommendation>
            <Value>Affinity</Value>
            <ValidationRules />
          </ValueRecommendation>
          <ValueRecommendation>
            <Value>Agatha</Value>
    ...

但我似乎错过了一些东西。我尝试使用 xPath,但它不会显示节点

xPath 文档

Dim MyXML As New XmlDocument()
MyXML.LoadXml(RichTextBox1.Text)
Dim MyXMLNode As XmlNodeList = MyXML.SelectNodes("//*/NameRecommendation")

For Each node In MyXMLNode
    '// add item to comboboxBrand
Next

试过了

Dim MyXMLNode As XmlNodeList = MyXML.SelectNodes("//NameRecommendation")

编辑 :

通过调试器,我实际上在 xml 文档中找到了该节点

在此处输入图像描述

标签: xmlvb.netxpath

解决方案


推荐阅读