Beispiel #1
0
        public static bool TryGetFirstElementValueByXPathNavigator(
            XmlDocument xmlDocument,
            string xpath,
            PrefixedNamespace[] prefixedNamespaces,
            out string value
            )
        {
            DocumentXPathResolver.CheckParameters(xmlDocument, prefixedNamespaces);
            bool result;

            if (string.IsNullOrEmpty(xpath))
            {
                value  = string.Empty;
                result = true;
            }
            else
            {
                string[] lineIter   = DocumentXPathResolver.GetXPathValues(xmlDocument, xpath, prefixedNamespaces);
                int      nodesCount = lineIter.Length;

                if (nodesCount >= 1)
                {
                    value  = lineIter[0];
                    result = true;
                }
                else
                {
                    value  = string.Empty;
                    result = false;
                }
            }

            return(result);
        }
Beispiel #2
0
        public static string GetElementValueByXPathNavigator(
            XmlDocument xmlDocument,
            string xpath,
            PrefixedNamespace[] prefixedNamespaces
            )
        {
            DocumentXPathResolver.CheckParameters(xmlDocument, prefixedNamespaces);
            string result;

            if (string.IsNullOrEmpty(xpath))
            {
                result = string.Empty;
            }
            else
            {
                string[] lineIter   = DocumentXPathResolver.GetXPathValues(xmlDocument, xpath, prefixedNamespaces);
                int      nodesCount = lineIter.Length;
                if (nodesCount < 1)
                {
                    throw new NoXPathResultsException(xpath);
                }
                if (nodesCount > 1)
                {
                    throw new TooManyXpathResultsException(xpath, nodesCount);
                }
                result = lineIter[0];
            }

            return(result);
        }