Groups | Blog | Home
all groups > asp.net > january 2004 >

asp.net : xpath problems


Marri Suliez
1/15/2004 11:06:02 PM
I am trying to run the asp xpath examples from the QuickStarts samples, but
I am not having any luck. When I run the code in a console app it works
fine. When I run the same exact code in an aspx page it doesn't work.

Here's a condensed example of what I am talking about. If I run this code
in a console app the "count" variable will have a value equal to the number
of book nodes in "books.xml". When I run the same code in an aspx page the
count is always 0.

XPathDocument doc = new XPathDocument("books.xml");
XPathNavigator navigator = doc.CreateNavigator();
XPathNodeIterator iterator = navigator.Select("bookstore/book");
int count = iteractor.Count;

Marri Suliez
1/15/2004 11:55:18 PM
Oleg Tkachenko <oleg@no_!spam!_please!tkachenko.com> wrote in
news:e32dU#72DHA.2296@TK2MSFTNGP11.phx.gbl:

[quoted text, click to view]

I already am doing that. If I wasn't I'd be getting an exception because
the file wouldn't be located. I'm not getting an error. The XPathDocument
is getting loaded properly. The problem comes in when I try call
Oleg Tkachenko
1/16/2004 1:30:35 AM
[quoted text, click to view]

Most likely it has nothing to do with XPath. Whenever you are working
with file system in ASP.NET, use Server.MapPath to get files. Try
XPathDocument doc = new XPathDocument(Server.MapPath("books.xml"));
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Oleg Tkachenko
1/18/2004 1:39:50 PM
[quoted text, click to view]

Now that weird. Make sure you it's the same document and exactly the
same code that works in command line.
--
Oleg Tkachenko
XmlInsider
AddThis Social Bookmark Button