xpath problems

M

Marri Suliez

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;

Any ideas?
 
O

Oleg Tkachenko

Marri said:
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");

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"));
 
M

Marri Suliez

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"));

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
XPathNavigator.Select.
 
O

Oleg Tkachenko

Marri said:
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
XPathNavigator.Select.

Now that weird. Make sure you it's the same document and exactly the
same code that works in command line.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top