XPath and listing the child node names / values

I am reading from an RSS XML Document and am having trouble listing the child elements of the <item> node.

What I need to do is get a list of all the child node names and values of the <item> node.

I'm fairly new to XPath and cant find a way to iterate through the child elements.... Below is my code:

                ArrayList otherNodes = new ArrayList();

                xpNav.Select("/rss/channel/item");
                xpNav.SelectChildren(XPathNodeType.Element);

                while (xpNav.MoveToNext())
                {
                    //string tt = x.ChildNodes[k].Name;
                    otherNodes.Add(xpNav.Name + "&&" + xpNav.Value);
                }
LVL 3
SuperGhostyAsked:
Who is Participating?
 
AgariciConnect With a Mentor Commented:
XPathDocument Doc = new XPathDocument("<yourXmlFile>");
XPathNavigator navigator = Doc.CreateNavigator();
XPathNodeIterator iterator = navigator.Select("<yourPathInsideTheXml>");
while (iterator.MoveNext())
{
//... do something with iterator.Curent
}

hth,
A.
0
 
aaronfengConnect With a Mentor Commented:
If you are having trouble with XPATH try the Visual XPath tool.  Here is the description from gotdotnet for Visual XPath:

"Used to test XPath queries and Performance times. It runs XPath queries and displays the result. Also the queries can be automatically generated by selecting XML nodes in the TreeView."


Cheers,

Aaron
http://aaronfeng.blogspot.com/
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.