用于访问Feed率值的XPath表达式

时间:2015-04-02 13:54:28

标签: xml xpath

我正在尝试使用XPath访问0.8785的Feed率(参见下面的代码):

<Streams>
  <DeviceStream name="Mori" uuid="001">
    <ComponentStream component="Path" name="path" componentId="pth">
      <Samples>
        <PathFeedrate dataItemId="fd1"
                      timestamp="2015-04-02T13:32:17.1810014Z"
                      name="feedrate"
                      sequence="6499">0.875</PathFeedrate>
        <PathFeedrate dataItemId="fd2"
                      timestamp="2015-04-02T12:09:33.7752758Z"
                      name="Fovr"
                      sequence="36"
                      subType="OVERRIDE">100</PathFeedrate>
        <FeedrateOverride dataItemId="fd3"
                          timestamp="2015-04-02T12:09:33.7752758Z"
                          name="Rovr"
                          sequence="37"
                          subType="RAPID">100</FeedrateOverride>
      </Samples>

2 个答案:

答案 0 :(得分:0)

以下XPath表达式

//PathFeedrate[@dataItemId='fd1']
鉴于您提供的XML,

将评估为0.875

答案 1 :(得分:0)

有几种方法

/Streams/DeviceStream/ComponentStream/Samples/PathFeedrate[1]

//PathFeedrate[1]

/Streams/DeviceStream/ComponentStream/Samples/PathFeedrate[. = '0.875']

//PathFeedrate[. = '0.875']

/Streams/DeviceStream/ComponentStream/Samples/PathFeedrate[@timestamp= '2015-04-02T13:32:17.1810014Z']

//PathFeedrate[@timestamp= '2015-04-02T13:32:17.1810014Z']

有很多方法可以找到你正在寻找的东西,但很多方面取决于xpath和/或xslt的上下文