tags:

views:

87

answers:

1

I suspect I am missing something basic but vital but because of it my XPath navigator is always returning the root.

I have some XML data like so:

<?xml version="1.0" encoding="utf-8" ?>
<language>
  <header>
    <about>about</about>
    <faqs>faqs</faqs>
    <feedback>feedback</feedback>
    <submitblog>submit a blog</submitblog>
    <advertise>advertise</advertise>
  </header>
</language>

and I have an XPathNavigator initialized with the document. I am calling it like so:

XPathNodeIterator iterator = (XPathNodeIterator)xNav.Evaluate("language/header/about");
            return iterator.Current.Value;

It gives me the root nood every single time (looks like so: 'aboutfaqsfeedbacksubmit a blogadvertise'.)

What am I doing wrong? Educate me.

+2  A: 

You should call MoveNext() on the iterator before returning its current value.

Source: http://msdn.microsoft.com/en-us/library/system.xml.xpath.xpathnodeiterator.aspx

280Z28
Thanks a million ton. You just wiped out the frustration of 1 hour with a single stroke.
Cyril Gupta