Slow SelectSingleNode
Posted
by Simon
on Stack Overflow
See other posts from Stack Overflow
or by Simon
Published on 2008-12-22T00:53:44Z
Indexed on
2010/05/07
11:08 UTC
Read the original article
Hit count: 415
I have a simple structured XML file like this:
<ttest ID="ttest00001", NickName="map00001"/>
<ttest ID="ttest00002", NickName="map00002"/>
<ttest ID="ttest00003", NickName="map00003"/>
<ttest ID="ttest00004", NickName="map00004"/>
..... This xml file can be around 2.5MB.
In my source code I will have a loop to get nicknames
In each loop, I have something like this:
nickNameLoopNum = MyXmlDoc.SelectSingleNode("//ttest[@ID=' + testloopNum + "']").Attributes["NickName"].Value
This single line will cost me 30 to 40 millisecond.
I searched some old articles (dated back to 2002) saying, use some sort of compiled "xpath" can help the situation, but that was 5 years ago. I wonder is there a mordern practice to make it faster? (I'm using .NET 3.5)
© Stack Overflow or respective owner