The Code i am using is:
string m_myXML = "<parent>\n" +
" <child1>\n"+
" <child2a>\n"+
" <list1 attrib=\"one\" />\n"+
" <list2 attrib=\"two\" />\n"+
" </child2a>\n"+
" <child2b>\n"+
" <list1 attrib=\"one\" />\n"+
" <list2 attrib=\"two\" />\n"+
" </child2b>\n"+
" </child1>\n"+
"</parent>";
XmlDocument doc = new XmlDocument();
doc.LoadXml(m_myXML);
XPathNavigator nav = doc.CreateNavigator();
XPathExpression expr;
expr = nav.Compile("/*/*"); //Select all children of top level parents
XPathNodeIterator iterator = nav.Select(expr);
The result is that iterator.Current.InnerXml is the same as iterator.Current.OuterXml and this is the same as the original m_myXML. When i Move the iterator to the next via iterator.MoveNext() it points to the first child1 - wich is what i would expect from it right at the beginning.
Am i doing something wrong? Is there a good and detailed explanation for dummys out there how System.Xml etc is supposed to function?
As Martin Honnen pointed out: A good source is msdn/system.xml... "An XPathNodeIterator object returned by the XPathNavigator class is not positioned on the first node in a selected set of nodes. A call to the MoveNext method of the XPathNodeIterator class must be made to position the XPathNodeIterator object on the first node in the selected set of nodes."
This makes perfekt Sense now - because otherwise you would have trouble to iterate through the List using something like this:
while (iterator.MoveNext())
{
//Do Stuff
}
Thank you Martin Honnen for your Answer in the comment section - i totally missed the point on that class.