当相关元素包含值时,元素的XPath?

时间:2016-09-20 16:56:37

标签: xml xpath

我有以下XML:

<originDestinationDetails>
    <originDestination></originDestination>
    <itineraryInfo>
      <elementManagementItinerary>
        <reference>
          <qualifier>ST</qualifier>
          <number>1</number>
        </reference>
        <segmentName>RU</segmentName>
        <lineNumber>2</lineNumber>
      </elementManagementItinerary>
      <travelProduct>
        <product>
          <depDate>201116</depDate>
        </product>
        <boardpointDetail>
          <cityCode>CWB</cityCode>
        </boardpointDetail>
        <companyDetail>
          <identification>1A</identification>
        </companyDetail>
      </travelProduct>
      <itineraryMessageAction>
        <business>
          <function>32</function>
        </business>
      </itineraryMessageAction>
      <relatedProduct>
        <quantity>1</quantity>
        <status>HK</status>
      </relatedProduct>
      <itineraryFreetext>
        <freetextDetail>
          <subjectQualifier>3</subjectQualifier>
        </freetextDetail>
        <longFreetext>-CAR/HERTZ/PUP-20NOV-0700/RT-22NOV-1800/VT-ICAR/CF-125456/SI-NVS</longFreetext>

我想从

返回cityCode

originDestinationDetails/itineraryInfo/travelProduct/boardpointDetail/cityCode

但仅限于longFreetext节点包含'CAR'的位置。

我已经在这里工作了几个小时,并尝试了各种不同的'contains'。只是无法让它工作。任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:1)

这个XPath,

build.gradle

将仅选择/originDestinationDetails /itineraryInfo[contains(itineraryFreetext/longFreetext, 'CAR')] /travelProduct/boardpointDetail/cityCode 元素中cityCode个元素,其中itineraryInfo的字符串值包含字符串longFreetext