读取xml流

时间:2009-07-21 16:23:46

标签: xml xmldocument xelement betfair

很抱歉再次提出类似的问题,我正在尝试阅读以下XML文档:

<markets currency="GBP">
  <market id="2908368" nextId="2908395">
    <status>ACTIVE</status>
    <commissionRate>2.5</commissionRate>
    <marketType>ANY_NUMBER_OF_WINNERS</marketType>
    <selections type="MainBets">
      <selection id="658442">
        <name>Player 1</name>
        <resource href="https://api.betfair.com/rest/v1/selection/tradeActivity
           ?username=sampleuser&marketId=2908368&selectionId=658442"
           responseType="selectionTradeActivity" title="Trade Activity"/>
        <status>IN_PLAY</status>   <!-- THIS IS THE VALUE I WANT -->
        <amountMatched>0.0</amountMatched> 
        <bestAvailableToBackPrices/>
        <bestAvailableToLayPrices/>
      </selection>
    </selections>
  </market>
</markets>

每个玩家都有4个玩家都有我想要的值,但我只能获得相同的状态,而不是每个玩家的个人状态。请有人帮助我。非常感谢

1 个答案:

答案 0 :(得分:0)

你可以使用xpath这里是一个例子

 XmlDocument xmlDoc;
     XmlNode     xmlNode;
     String      xpathExpr;

     xmlDoc = new XmlDocument();
     xmlDoc.LoadXml( "<?xml version='1.0'?><root><person><name>Martin Fowler</name></person><person><name>Kent Beck</name></person><person><name>Dave Astels</name></person></root>" );

     xpathExpr = "/root/person[name='Martin Fowler']";
     xmlNode = xmlDoc.SelectSingleNode(xpathExpr);