我是非常新的解析XML,我开始学习linq,我认为这可能是最好的解决方案。我最感兴趣的是性能,因为我创建的应用程序将读取股票交易所的价格,这些价格有时可能会非常迅速地变化。 我从服务器接收以下信息:什么是最快/最有效的方式来阅读这个XML字典(Linq或其他?)
<?xml version="1.0" encoding="utf-16"?>
<events>
<header>
<seq>0</seq>
</header>
<body>
<orderBookStatus>
<id>100093</id>
<status>Opened</status>
</orderBookStatus>
<orderBook>
<instrumentId>100093</instrumentId>
<bids>
<pricePoint>
<price>1357.1</price>
<quantity>20</quantity>
</pricePoint>
<pricePoint>
<price>1357.0</price>
<quantity>20</quantity>
</pricePoint>
<pricePoint>
<price>1356.9</price>
<quantity>71</quantity>
</pricePoint>
<pricePoint>
<price>1356.8</price>
<quantity>20</quantity>
</pricePoint>
</bids>
<offers>
<pricePoint>
<price>1357.7</price>
<quantity>51</quantity>
</pricePoint>
<pricePoint>
<price>1357.9</price>
<quantity>20</quantity>
</pricePoint>
<pricePoint>
<price>1358.0</price>
<quantity>20</quantity>
</pricePoint>
<pricePoint>
<price>1358.1</price>
<quantity>20</quantity>
</pricePoint>
<pricePoint>
<price>1358.2</price>
<quantity>20</quantity>
</pricePoint>
</offers>
<lastMarketClosePrice>
<price>1356.8</price>
<timestamp>2011-05-03T20:00:00</timestamp>
</lastMarketClosePrice>
<dailyHighestTradedPrice />
<dailyLowestTradedPrice />
<valuationBidPrice>1357.1</valuationBidPrice>
<valuationAskPrice>1357.7</valuationAskPrice>
<lastTradedPrice>1328.1</lastTradedPrice>
<exchangeTimestamp>1304501070802</exchangeTimestamp>
</orderBook>
</body>
</events>
我的目标是解析的价格点元件
<pricePoint>
<price>1358.2</price>
<quantity>20</quantity>
</pricePoint>
成以下结构的词典:
Dictionary<double, PriceLevel>
在价格应该是一个双和PriceLevel是一类
class PriceLevel
{
int bid;
int offer;
public PriceLevel(int b, int o)
{
bid = b;
offer = o;
}
}
根据元素的不同,每个价格点都存在(要么是出价或要约),因此应该相应地分配数量,即如果价格点存在于出价中,那么数量应该被分配给出价,并且0被提供。相反,如果报价中存在价格点,那么应该分配数量以提供报价,0报价。
我希望我的解释清楚,但是如果您在理解时有任何问题,请不要犹豫,在评论中要求澄清。 我非常感谢帮助解决这个问题。
+++++++++++++++++++++++++++++++++++++++++ 更新:
我已经深入到我正在尝试阅读的流中,而且它不会像我期望的那么简单。我发现,该流并不总是包含整个文档,因此我将不得不使用XmlReader读取它以持续处理流。在这种情况下,我如何阅读出价和优惠?我有这样的事情:
StreamReader sr = new StreamReader(“.. \ .. \ videos.xml”);
XmlReader xmlReader = XmlReader.Create(sr);
while (xmlReader.Read())
{
if (xmlReader.HasValue)
{
OnXmlValue(this, new MessageEventArgs(true, xmlReader.Value));//saxContentHandler.Content(xmlReader.Value);
}
else
{
if (xmlReader.IsEmptyElement)
{
OnStartElement(this, new MessageEventArgs(false, xmlReader.Name));
OnEndElement(this, new MessageEventArgs(false, xmlReader.Name));
}
else if (xmlReader.IsStartElement())
{
OnStartElement(this, new MessageEventArgs(false, xmlReader.Name));
}
else
{
OnEndElement(this, new MessageEventArgs(false, xmlReader.Name));
}
}
}
,但我很努力的元素名称链接到它的价值...即,我怎么能知道哪些标价点我目前正在读,如果存在的话在投标或报价? 谢谢你的帮助
什么是您的价格点的最大准确性?你有他们所有的小数点后1位,在dp之前有4位数字,在你的例子中。这是如何为您的所有价格点? – 2011-05-04 10:09:30
速度最快有多快?秒,毫秒,微秒? – Ishtar 2011-05-04 10:28:10
我认为,6位小数的最大精度应该足够了。至于速度和性能,每秒钟会有很多类似的消息,所以我至少要说几毫秒;) – Macin 2011-05-04 11:24:21