如何使用“包含”获取唯一节点

本文关键字:获取 唯一 节点 包含 何使用 | 更新日期: 2023-09-27 17:57:04

正在尝试检索父节点的属性值。

问题:如何通过仅使用相等搜索而不是包含搜索来匹配所有子文本来获取父节点

XML结构:

 <Elementstart>
   <Cardstart>
      <Simulate Number="1">
         <One>4</One>
         <Two>2</Two>
         <Three>11</Three>
      </Simulate>
      <Simulate Number="5">
         <One>44</One>
         <Two>22</Two>
         <Three>111</Three>
      </Simulate>
   </Cardstart>
 </Elementstart>

1)我需要通过查询子元素来获取父元素使用以下 XPATH

 //Simulate[contains(One, '4') and contains(Two, '2') and contains(Three,'1')]

我得到了父母<Simulate Number="1"><Simulate Number="5">但是,我只需要获取<Simulate Number="1">,因为我只查询了个位数 2。有没有办法只得到第一个?

另一个问题是如何在and条件下使用equaltext()=''

如何使用“包含”获取唯一节点

您可以使用以下 XPath,它将通过匹配三个子元素中每个元素的精确值来返回Simulate

//Simulate[One='4' and Two='2' and Three='11']

结果将是<Simulate Number="1">元素。