我有一个非常简单的XML:Linq to XML,查找元素的最快方法?
<Rows>
<Row>
<id>1</id>
<name>foo</name>
<more>xyz</more>
</Row>
<Row>
<id>2</id>
<name>bar</name>
<more>abc</more>
</Row>
</Rows>
,需要做大量的查询上的标识,速度是关键真是的。
将XML加载到数据表中并在ID上创建PK并对数据表进行查询会更有效吗?
或
这是最有效的Linq/Xml代码吗?
myRows = XDocument.Parse(xmlString);
result = myRows.Element("Rows").Elements("Row").Single(r => r.Element("id").Value == "1");
if (result != null)
string name = result.Element("name").Value;
编辑为清楚:还有比ID &名字更多的元素。
尼斯的思想,但忘了提有更多的属性比id&name。 – 2010-09-08 01:11:57
@Andrew可以反序列化为一个'Dictionary'? –
2010-09-08 01:57:50