简体   繁体   中英

Why does my XPathNavigator always return the Root?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM