【发布时间】:2016-05-27 06:41:09
【问题描述】:
我有一个 xml 文档,其中包含这样的部分。
<MultiplyFunction>
<Name>HeightModel</Name>
<LinearInterpolationFunction>
<Name>WaterStress</Name>
</LinearInterpolationFunction>
</MultiplyFunction>
<MultiplyFunction>
<Name>ExtinctionCoeff</Name>
<LinearInterpolationFunction>
<Name>WaterStress</Name>
</LinearInterpolationFunction>
</MultiplyFunction>
我想构建一个 xpath 来查找第二个元素 <Name>WaterStress</Name>。此元素的唯一关键字是 ExtinctionCoeff 和 WaterStress。
我当前的 xpath 是 //Name[text()="WaterStress"],它可以找到这两个元素。我应该如何通过添加关键字ExtinctionCoeff来指定第二个?
【问题讨论】:
-
我认为
//Name[text()="WaterStress"][2] 会起作用 -
//MultiplyFunction[Name="ExtinctionCoeff"]/LinearInterpolationFunction/Name[text()="WaterStress"] -
感谢所有帮助。 @splash58 你的代码对我有用。您能否添加作为答案,然后我可以接受它。
-
@Bangyou 我做到了。祝你好运!