Link to home
Start Free TrialLog in
Avatar of peter3244
peter3244Flag for United Kingdom of Great Britain and Northern Ireland

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of MogalManic
MogalManic
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial