XML xPath语法可获取所有元素

时间:2018-10-29 19:21:17

标签: xml vb.net 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 documentation

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文档中找到了该节点

enter image description here

0 个答案:

没有答案