简单的Xpath查找特定信息

时间:2019-10-31 09:40:05

标签: xml xpath

我需要找到哪个演员在《狮子王》中扮演辛巴。我确实知道我是否打字 //Disney/Subsidiaries/Subsidiary/Movie[Cast/Role[contains(@Name,'Simba')]]/Name我知道了电影的名字,但我想检索扮演辛巴的演员的名字。

    <Movie>
    <Name lang="en">The Lion King</Name>
    <Year>2019</Year>
    <ScreenTime unit="minutes">118</ScreenTime>
    <Cast>
      <Role name="Simba" actor="DonaldGlover" />
      <Role name="Mufasa" actor="JamesEarlJones" />
      <Role name="Nala" actor="BeyoncéKnowles" />
      <Role name="Timon" actor="BillyEichner" />
      <Role name="Pumbaa" actor="SethRogen" />
    </Cast>
  </Movie>

我尝试过 // Disney / Subsidiaries / Subsidiary / Movie [Cast / Role [contains(@ actor,'Simba')]] / actor

在这种情况下,我希望它会返回。  “ DonaldGlove”

1 个答案:

答案 0 :(得分:0)

尝试以下表达式:

 //Movie/Cast/Role[@name='Simba']/@actor

它输出:

  

DonaldGlover