2017-08-31 25 views
0

我想我已经陷在我解析使用XPath的XML服务器问题......在解析XML我可以有多个重复的标签,但有不同的数据让我们的例子....如何在Xpath中动态获取基于位置的标签值?

<note> 
<to>Tove 1</to> 
<from>Jani 1</from> 
<heading>Reminder 1</heading> 
<body>Don't forget me this weekend One!</body> 
</note> 
<!-Second Node -!> 
<note> 
<to>Tove 2</to> 
<from>Jani 2</from> 
<heading>Reminder 2</heading> 
<body>Don't forget me this weekend Second!</body> 
</note> 

//注意/到/文()从<to>标签获取文本 - >我的Xpath

但问题是我不知道有多少标签可能有,在上述的Xpath我得到第一次不值每次...

注:我知道我可以使用[1],[2]如果我知道的标签的数量,但如何做到动态

+0

你想获得哪一个? – Andersson

回答

0

如果你想获得的元素数量:

count(//note//to/text())

如果你想获得基于文本的单元:

//note//to/[text() = 'Jani 1']/text()

相关问题