如何通过xPath从XML元素获取子字符串?

时间:2015-09-08 13:43:17

标签: xml xpath

源XML:

<?xml version="1.0" encoding="UTF-8"?>
<ServerAnswer>
  <Booking Data="AABB150908"/>
  <Booking Data="AABB150907"/>
</ServerAnswer>

我的XPath:

//Booking/@Data[substring(//Booking/@Data,4,6)]

如果我通过http://www.xpathtester.com/xpath查询xPath,我只能获得完整的数据。我怎样才能在数据中获得给定的日期?

1 个答案:

答案 0 :(得分:0)

Xpath从1开始计数,而不是从0

开始计算
substring(//Booking/@Data,5,6)