Example #1
0
        private IEnumerable <T> EvaluateIterator <T>(XPathNodeIterator result)
        {
            foreach (XPathNavigator navigator in result)
            {
                object r = navigator.UnderlyingObject;
                if (!(r is T))
                {
                    throw new InvalidOperationException(SR.Format(SR.InvalidOperation_UnexpectedEvaluation, r.GetType()));
                }
                yield return((T)r);

                XText t = r as XText;
                if (t != null && t.GetParent() != null)
                {
                    do
                    {
                        t = t.NextNode as XText;
                        if (t == null)
                        {
                            break;
                        }
                        yield return((T)(object)t);
                    } while (t != t.GetParent().LastNode);
                }
            }
        }
Example #2
0
        static XText CalibrateText(XText n)
        {
            if (n.GetParent() == null)
            {
                return(n);
            }
            XNode p = n.GetParent().LastNode;

            while (true)
            {
                p = p.NextNode;
                XText t = p as XText;
                if (t != null)
                {
                    do
                    {
                        if (p == n)
                        {
                            return(t);
                        }
                        p = p.NextNode;
                    } while (p is XText);
                }
            }
        }
Example #3
0
        static string CollectText(XText n)
        {
            string s = n.Value;

            if (n.GetParent() != null)
            {
                while (n != n.GetParent().LastNode)
                {
                    n = n.NextNode as XText;
                    if (n == null)
                    {
                        break;
                    }
                    s += n.Value;
                }
            }
            return(s);
        }
Example #4
0
        private static string CollectText(XText n)
        {
            string s = n.Value;

            if (n.GetParent() != null)
            {
                foreach (XNode node in n.NodesAfterSelf())
                {
                    XText?t = node as XText;
                    if (t == null)
                    {
                        break;
                    }
                    s += t.Value;
                }
            }
            return(s);
        }
Example #5
0
        private static XText CalibrateText(XText n)
        {
            XContainer?parentNode = n.GetParent();

            if (parentNode == null)
            {
                return(n);
            }
            foreach (XNode node in parentNode.Nodes())
            {
                XText?t          = node as XText;
                bool  isTextNode = t != null;
                if (isTextNode && node == n)
                {
                    return(t !);
                }
            }

            System.Diagnostics.Debug.Fail("Parent node doesn't contain itself.");
            return(null);
        }
Example #6
0
        /// <summary>
        /// Creates an <see cref="XPathNavigator"/> for a given <see cref="XNode"/>
        /// </summary>
        /// <param name="node">Extension point <see cref="XNode"/></param>
        /// <param name="nameTable">The <see cref="XmlNameTable"/> to be used by
        /// the <see cref="XPathNavigator"/></param>
        /// <returns>An <see cref="XPathNavigator"/></returns>
        public static XPathNavigator CreateNavigator(this XNode node, XmlNameTable nameTable)
        {
            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }
            if (node is XDocumentType)
            {
                throw new ArgumentException(SR.Format(SR.Argument_CreateNavigator, XmlNodeType.DocumentType));
            }
            XText text = node as XText;

            if (text != null)
            {
                if (text.GetParent() is XDocument)
                {
                    throw new ArgumentException(SR.Format(SR.Argument_CreateNavigator, XmlNodeType.Whitespace));
                }
                node = CalibrateText(text);
            }
            return(new XNodeNavigator(node, nameTable));
        }
Example #7
0
 static bool IsSamePosition(XNodeNavigator n1, XNodeNavigator n2)
 {
     if (n1.source == n2.source && n1.parent == n2.parent)
     {
         return(true);
     }
     // compare lazy text with eager text
     if (n1.parent != null ^ n2.parent != null)
     {
         XText t1 = n1.source as XText;
         if (t1 != null)
         {
             return((object)t1.Value == (object)n2.source && t1.GetParent() == n2.parent);
         }
         XText t2 = n2.source as XText;
         if (t2 != null)
         {
             return((object)t2.Value == (object)n1.source && t2.GetParent() == n1.parent);
         }
     }
     return(false);
 }