[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1395
  • Last Modified:

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);
                }
0
SuperGhosty
Asked:
SuperGhosty
3 Solutions
 
AgariciCommented:
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
 
aaronfengCommented:
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now