RATHI
RATHI

Reputation: 5289

How to parse all child of a element with XPATH

i am parsing a xml file with XPATH

nodes = navigator.Select("/bk:ChaosPlan/bk:SubscriptionInfo",manager);
while (nodes.MoveNext())
        {
            XPathNavigator childNodes = nodes.Current.Clone();
            childNodes.MoveToFirstAttribute();
            string name = childNodes.Value;
            bool x = true;
            x= childNodes.MoveToFirstChild();
            string Id = childNodes.Value;
            subNamenAndId.Add(new Result(name, Id));
            childNodes.MoveToNext();
            certName = childNodes.Value;
            childNodes.MoveToNext();
            templateName = childNodes.Value;

}

but when i am moving to first child (after bool x= true; line) it is returning false and not moving to first child.

what i need to do, Is to get the attribute of first element after running query and then iterate through first 3 child of this element and store those value.

Upvotes: 0

Views: 368

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167446

When your XPathNavigator is positioned on the attribute call http://msdn.microsoft.com/en-us/library/system.xml.xpath.xpathnavigator.movetoparent.aspx first to be able to then move on to child nodes.

Upvotes: 2

Related Questions