XPath Select 具有特定父节点的所有子节点(按属性)

XPath Select all children with specific parent node by attribute

我想要 select 所有子级,即父级 dividtestRoot 的图像。结构未知。为了便于理解,我在这里对其进行了简化。如果是XPath表达式就好了

        <div id="testRoot">

<div class="panel">
                    <a tabindex="-1" href="/mafuae/en/p/1236018">
                        <picture>
                            <source srcset="/medias/sys_master/images/images/h4e/hf5/8820729217054/NikonSlr-H-Tablet.jpg" media="(min-width: 768px)">
                            <img src="" alt="NikonSlr_H_Desktop.jpg">
                        </source>
                        </source></source></picture>
                    </a>
                </div>
            <div class="panel">
                    <a tabindex="-1" href="/mafuae/en/storespromotions">
                        <picture>
                            <source srcset="/medias/sys_master/images/images/h73/hd7/8818984321054/Ramadan2-14thMay-Tablet.jpg" media="(min-width: 768px)">
                            <img src="" alt="Ramadan2_14thMay_Desktop.jpg">
                        </source></source></source></picture>
                    </a>
                </div>
</div>

这是我尝试过的但是...

doc.DocumentNode.SelectNodes("//div[@id='hero']/div/div")

对于 id 属性为 hero //div[@id='hero']div 元素,这些 XPath 表达式将 select 元素如下:

  • //div[@id='hero']/* 将 select 它的所有 元素。
  • //div[@id='hero']/img 将 select 它的所有 子元素 img 元素。
  • //div[@id='hero']//* 将 select 它的所有 descendent 元素。
  • //div[@id='hero']//img 将 select 它的所有 后代 img 元素。