Groups | Blog | Home
all groups > dotnet xml > may 2004 >

dotnet xml : XPath helper upon XmlTextReader


Bnaya Eshet
5/12/2004 5:21:18 PM
I do like XPath, I really do.



But I'm working on the compact framework which XPath is not included.



So I come to understanding that if XPath do not come to the mountain,

The mountain will come to XPath.



I decided to build an XPath evaluation helper with will get XmlTextReader
and XPath string, and it will return XmlTextReader that will be the result
of the XPath.



The signature should be something like that:

XmlTextReader XPathHelper (XmlTextReader reader, string xpath)



The thing that I'm querying the community is does a similar code already
exist on the internet, and I'm going to spend my time on an existing issue.



Any way I will be glad to hear if you have a suggestion for the architecture
of such helper.



I thought of something simple which will ignore ancestor axis for the start.

And it seems to me like a recursive method which dealing with one operation
at a time and then recurs the call with the result reader and the XPath
ahead of the already handled operation.



Which mean the "//Book/Author[@name='Mike']" XPath will:

1.. Iterate around all Book tags
2.. forward the result reader with the " /Author[@name='Mike']" ahead
3.. Iterate around all Author tags
4.. forward the result reader with the " [@name='Mike']" ahead
5.. then return reader if there is attribute "name='Mike'" else return
null

Oleg Tkachenko [MVP]
5/12/2004 5:40:58 PM
[quoted text, click to view]

Take a look at recently published "The Best of Both Worlds: Combining
XPath with the XmlReader" article by Dare Obasanjo and Howard Hao -
http://msdn.microsoft.com/library/en-us/dnexxml/html/xml05192004.asp

--
Oleg Tkachenko [XML MVP]
Bnaya Eshet
5/13/2004 12:57:17 PM
As I mention I'm using the Compact Framework which do not have support for
XpathReader so that article does not supplying the right answer.



TNX any way





[quoted text, click to view]

Oleg Tkachenko [MVP]
5/13/2004 1:03:05 PM
[quoted text, click to view]

No, read the article. It describes implementation of XPath over plain
XmlTextReader (which is supported in the CF).

--
Oleg Tkachenko [XML MVP]
Daniel Cazzulino [MVP XML]
5/16/2004 7:43:56 PM
Beware, however, that it's based on the same core of XPath in .NET (though I
wonder why it's not included in CF... maybe it's too computationally
expensive? - build AST, keep the whole thing in-memory, advance the
cursor...).
Watch out the licensing terms if you're going to distribute/sell it, as it's
the MS's Shared Source.

--
Daniel Cazzulino [MVP XML]
Clarius Consulting SA
http://weblogs.asp.net/cazzu
http://aspnet2.com

[quoted text, click to view]


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.679 / Virus Database: 441 - Release Date: 07/05/2004

AddThis Social Bookmark Button