如何进行XPath查询

时间:2015-08-20 08:34:26

标签: xml xpath

我有一个xml文件。

<ISL2015>
   <Teams>
      <ATL>
         <Dom>
            <Player>
                <Name>ATL PLAYER 1</Name>
                <MatchesPlayed>35</MatchesPlayed>
                <GoalsScored>11</GoalsScored>
            </Player>
            <Player>
                <Name>ATL PLAYER 2</Name>
                <MatchesPlayed>14</MatchesPlayed>
                <GoalsScored>09</GoalsScored>
            </Player>

我想使用播放器的名称获取某个玩家的所有值。 我尝试过使用

/ISL2015/Teams/ATL/Dom/Player[@Name="ATL PLAYER 1"]

1 个答案:

答案 0 :(得分:0)

名称不是属性而是节点。所以你需要通过xpath

/ISL2015/Teams/ATL/Dom/Player[Name="ATL PLAYER 1"]/*

结果

Element='<Name>ATL PLAYER 1</Name>'
Element='<MatchesPlayed>35</MatchesPlayed>'
Element='<GoalsScored>11</GoalsScored>'