Using xPathNav.Compile, its returning a node set how can I access the nodeset C# 2005?

Using xPathNav.Compile, its returning a node set  how can I access the nodeset C# 2005?

               When xpathExpr.ReturnType = XPathResultType.NodeSet

how do I access the properties of this node set

object functionReturnValue = xPathNav.Select(xpathExpr);

ie does not return what i want as i just want the node not a XPathNavigator
public object GetXpath(XmlNode node, string xPath)
        {
            object functionReturnValue = null;
            string errorMsg = "TransmitMessage::XPath expression {0} is invalid. " + xPath;
            try {                
                XPathNavigator xPathNav = node.CreateNavigator();
                XPathExpression xpathExpr = xPathNav.Compile(xPath);
 
                 switch (xpathExpr.ReturnType)
                {
 
                    case XPathResultType.Boolean:
                        functionReturnValue = xPathNav.Evaluate(xpathExpr);
                        break;
                    case XPathResultType.String:
                        functionReturnValue = xPathNav.Evaluate(xpathExpr);
                        break;
                    case XPathResultType.Number:
                        functionReturnValue = xPathNav.Evaluate(xpathExpr);
                        break;
                    case XPathResultType.NodeSet:
                        // how do I access this nodeset
                        functionReturnValue = xPathNav.Select(xpathExpr);
                        break;
                    case XPathResultType.Error:
                        GenericLogger.ErrorLog(errorMsg);
                        functionReturnValue = errorMsg;
                        throw new Exception(errorMsg);
                    default:
                        functionReturnValue = errorMsg;
                        throw new Exception(errorMsg);
                }
 
            }
 
 
 
 
 
            catch (Exception exp)
            {
 
                functionReturnValue = exp.Message + " " + errorMsg;
                GenericLogger.ErrorLog(_userName, _machineName, errorMsg);
                throw new Exception(errorMsg);
 
            }
            
            return functionReturnValue;
 
        }

Open in new window

peter3244Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MogalManicCommented:
The function returns a XPathNodeIterator.  The iterator implements the IEnumerable interface, so all you need to do is
foreach(XPathNavigator node in results) {
   string NodeValue = node.Value;
  string NodeName = node.Name;
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.