gpt4 book ai didi

c# - 从 XML 中的最新日期时间戳获取 xmlnode

转载 作者:数据小太阳 更新时间:2023-10-29 02:39:38 25 4
gpt4 key购买 nike

我正在尝试从 XML 文件中获取 XMLNODE“Price”,XML 本身就很大,并且其中有很多很多“Row”元素。我试图通过最新的“transactionDateTime”获取“Price”节点,因为它有时间戳,但我无法让它工作。

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>

Please remember this XML is big and this is just a cut down version.

最佳答案

XElement xml = XElement.Load("dat.xml");

var mostRecentPrice = xml.Descendants("row")
.OrderByDescending(r => DateTime.Parse(r.Attribute("transactionDateTime").Value))
.First().Attribute("price").Value;

如果行是升序的,您还可以按它们的事务 ID 对行进行排序:

var mostRecentPrice = xml.Descendants("row")
.OrderByDescending(r => r.Attribute("transactionID").Value)
.First().Attribute("price").Value;

关于c# - 从 XML 中的最新日期时间戳获取 xmlnode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35147966/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com