Groups | Blog | Home
all groups > dotnet xml > october 2005 >

dotnet xml : Best approach for xpath on .NET 2.0



David Thielen
10/5/2005 4:37:02 PM
Hi;

I need to perform xpath queries on xml under .net 2.0 (ok if it won't run
under 1.1). What is the approach that will give me the fastest code?

These xpath queries will walk all over the xml - it is not a case where each
query usually occurs further down the xml from the previous query. And there
will tend to be a lot of queries on each dataset.

--
David Thielen
10/5/2005 7:39:03 PM
Hello;

Sorry - I should not have used the word dataset. My xml will always come
from a Stream - usually a file.

--
thanks - dave


[quoted text, click to view]
v-kevy NO[at]SPAM online.microsoft.com
10/6/2005 12:00:00 AM
Hi Dave,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to perform an XPath query on a
DataSet. If there is any misunderstanding, please feel free to let me know.

Here is a very good article dedicated on how to perform an XPath query on a
DataSet. Please check it and it will be helpful.

http://msdn2.microsoft.com/en-us/library/89tyw6dw

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
Martin Honnen
10/7/2005 12:00:00 AM

[quoted text, click to view]

No, XPathDocument is optimized for readonly XPath access. You only need
XmlDocument if you want to make changes to the XML.


--

Martin Honnen --- MVP XML
v-kevy NO[at]SPAM online.microsoft.com
10/7/2005 5:51:47 AM
Hi dave,

Doing XQuery in an XmlDocument is generally the same as mentioned in the
article I have provided. If you're getting the xml from a file, you can
first load it into an XmlDocument and then use XmlDocument.SelectNodes with
an xpath as argument to do the query. It is also the same as we did in .NET
1.1. Please also check the following link for more informatioin on
SelectNodes method.

http://msdn2.microsoft.com/en-us/library/hcebdtae

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
David Thielen
10/7/2005 6:45:02 AM
Hello;

So XmlDocument is more efficient than XpathDocument? Ok, will go that route.

Out of curiosity why do they have XpathDocument then?

--
thanks - dave


[quoted text, click to view]
David Thielen
10/7/2005 7:18:07 AM
Hi;

That's what I thought. But Kevin Yu is, I am assuming, posting the official
MS suggestion. Any idea why he would prefer XmlDocument?

My use is xpath quieries only - so it is read-only.

--
thanks - dave


[quoted text, click to view]
David Thielen
10/9/2005 8:56:01 PM
Hi;

Can I assume that for the read-only case XpathDocument is faster?

--
thanks - dave


[quoted text, click to view]
Oleg Tkachenko [MVP]
10/10/2005 12:00:00 AM
[quoted text, click to view]

Sure. It's 30-50% faster than XmlDocument for XPath. Not to mention it
takes less memory.

--
Oleg Tkachenko [XML MVP, MCAD]
http://www.xmllab.net
v-kevy NO[at]SPAM online.microsoft.com
10/10/2005 12:00:00 AM
Hi dave,

I think there might be some misunderstanding here. Using XmlDocument or
XpathDocument depends on the scenario. As Martin said, in an readonly case,
we can use xpathdocument, however, if you need to do modifications, use
XmlDocument.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
AddThis Social Bookmark Button