简单的xpath查找特定信息

时间:2019-10-31 03:02:25

标签: xml xpath

我被赋予查找包含角色名称“ skywalker”的所有电影的任务。

     </Subsidiary>

     <Subsidiary id="Lucasfilms">

    <Movie>
    <Name lang="en">Star Wars: The Force Awakens</Name>
    <Year>2015</Year>
    <ScreenTime unit="minutes">135</ScreenTime>
    <Cast>
      <Role name="Han Solo" actor="HarrisonFord" />
      <Role name="Rey" actor="DaisyRidley" />
      <Role name="Kylo Ren" actor="AdamDriver" />
      <Role name="Finn" actor="JohnBoyega" />
      <Role name="Luke Skywalker" actor="MarkHamill" />
      <Role name="Supreme Leader Snoke" actor="AndySerkis" />
      <Role name="C-3PO" actor="AnthonyDaniels" />
      <Role name="Poe Dameron" actor="OscarIsaac" />
      <Role name="General Hux" actor="DomhnallGleeson" />
     </Cast>
      </Movie>

 i've tried //Disney/Subsidiaries/Subsidiary/Movie/Cast [contains(./Role, 
 'Skywalker')] this does not work

我希望它返回给我其中包含天行者名字的电影的名字。

1 个答案:

答案 0 :(得分:0)

使用

vec.push_back(std::move(v));

返回/Subsidiary/Movie[Cast/Role[contains(@name,'Skywalker')]]/Name 元素的Name元素。