即時嘗試從XML文件中獲取XMLNODE「價格」,這個XML本身就是巨大的,它有很多「行」元素。我試圖通過最新的「transactionDateTime」來獲得「價格」節點,因爲它有一個時間戳,但我很難讓它工作。從XML中獲取xmlnode最近的日期時間戳記
XmlDocument xdocoA = new XmlDocument();
xdocoA.Load(Transation);
XmlNodeList ndlistA = xdocoA.SelectNodes("/eveapi/result/rowset/row[@transactionDateTime]");
foreach (XmlNode xmlnodeA in ndlistA)
{
LastTN.Text = xmlnodeA.Attributes["price"].InnerText;
}
XML文件:
<eveapi version="2">
<currentTime>2016-02-01 22:48:26</currentTime>
<result>
<rowset name="transactions" key="transactionID" columns="transactionDateTime,transactionID,quantity,typeName,typeID,price,clientID,clientName,stationID,stationName,transactionType,transactionFor,journalTransactionID,clientTypeID">
<row transactionDateTime="2016-01-31 23:10:57" transactionID="4212499228" quantity="12" typeName="Spodumain Mining Crystal II" typeID="18624" price="900000.00" clientID="94420021" clientName="Gayle Rowen" stationID="61000400" stationName="4F6-VZ XI - Limited Sense" transactionType="buy" transactionFor="personal" journalTransactionID="12205145551" clientTypeID="1373"/>
<row transactionDateTime="2016-01-30 17:52:03" transactionID="4210791656" quantity="1" typeName="Small Polycarbon Engine Housing I" typeID="31177" price="500000.00" clientID="95987816" clientName="Lash Wolfram" stationID="61000575" stationName="6-8QLA V - Perrigen Falls Trade Hub" transactionType="buy" transactionFor="personal" journalTransactionID="12198662373" clientTypeID="1376"/>
<row transactionDateTime="2016-01-30 17:50:44" transactionID="4210790391" quantity="1" typeName="BZ-5 Neutralizing Spatial Destabilizer ECM" typeID="19946" price="549999.99" clientID="920370728" clientName="Missniggins" stationID="61000884" stationName="OP7-BP V - Ivy Towers" transactionType="buy" transactionFor="personal" journalTransactionID="12198656389" clientTypeID="1377"/>
</rowset>
</result>
<cachedUntil>2016-02-01 23:15:21</cachedUntil>
</eveapi>
請記住這個XML大,這僅僅是一個減少的版本。
你到底是遇到了問題與什麼?解析時間戳?或者找到最近的一個? –
請注意,'rowset'元素沒有結束標記 – har07
如果您對LINQ感到滿意,請嘗試將Linq轉換爲xml api。 – VivekDev