ReasonCodeExample.XPathInformation.XmlRepository.GetNodeCount C# (CSharp) Method

GetNodeCount() public method

public GetNodeCount ( XObject xml, string xpath ) : int?
xml XObject
xpath string
return int?
        public int? GetNodeCount(XObject xml, string xpath)
        {
            if(xml == null)
            {
                return null;
            }
            if(xml.Document == null)
            {
                return null;
            }
            if(xml.Document.Root == null)
            {
                return null;
            }
            try
            {
                var namespaceResolver = new SimpleXmlNamespaceResolver(xml.Document);
                var results = (IEnumerable)xml.Document.XPathEvaluate(xpath, namespaceResolver);
                return results.OfType<XObject>().Count();
            }
            catch(Exception)
            {
                return null;
            }
        }