protected override void WritePredicates(XPathPart pathPart)
 {
     WritePredicateStart();
     XPath.Append(GetElementIndex((XElement)pathPart.Node));
     WritePredicateEnd();
     base.WritePredicates(pathPart);
 }
Ejemplo n.º 2
0
        private IEnumerable <XPathPart> GetPathParts(XObject node)
        {
            XElement selectedElement;

            if (IsElement(node))
            {
                selectedElement = (XElement)node;
            }
            else if (IsAttribute(node))
            {
                selectedElement = node.Parent;
            }
            else
            {
                throw new ArgumentException("Node is not an element or attribute: " + node.GetType(), nameof(node));
            }

            var parts            = new List <XPathPart>();
            var ancestorsAndSelf = selectedElement.AncestorsAndSelf().Reverse();

            foreach (var ancestor in ancestorsAndSelf)
            {
                var part = new XPathPart();
                part.Node       = ancestor;
                part.Predicates = ancestor.Attributes().Where(MatchesAnyFilter).ToArray();
                parts.Add(part);
            }
            if (IsAttribute(node))
            {
                parts.Add(new XPathPart {
                    Node = node
                });
            }
            return(parts);
        }
Ejemplo n.º 3
0
 protected override void WritePredicates(XPathPart pathPart)
 {
     WritePredicateStart();
     XPath.Append(GetElementIndex((XElement)pathPart.Node));
     WritePredicateEnd();
     base.WritePredicates(pathPart);
 }
Ejemplo n.º 4
0
 protected virtual void WritePredicates(XPathPart pathPart)
 {
     if (pathPart.Predicates == null)
     {
         return;
     }
     if (pathPart.Predicates.Count == 0)
     {
         return;
     }
     foreach (var predicate in pathPart.Predicates)
     {
         WritePredicateStart();
         WriteAttributeName(predicate);
         WriteAttributeValue(predicate);
         WritePredicateEnd();
     }
 }
 protected virtual void WritePredicates(XPathPart pathPart)
 {
     if(pathPart.Predicates == null)
     {
         return;
     }
     if(pathPart.Predicates.Count == 0)
     {
         return;
     }
     foreach(var predicate in pathPart.Predicates)
     {
         WritePredicateStart();
         WriteAttributeName(predicate);
         WriteAttributeValue(predicate);
         WritePredicateEnd();
     }
 }
 private bool IsElement(XPathPart pathPart)
 {
     return IsElement(pathPart.Node);
 }
 private bool IsAttribute(XPathPart pathPart)
 {
     return pathPart.Node is XAttribute;
 }
        private IEnumerable<XPathPart> GetPathParts(XObject node)
        {
            XElement selectedElement;
            if(IsElement(node))
            {
                selectedElement = (XElement)node;
            }
            else if(IsAttribute(node))
            {
                selectedElement = node.Parent;
            }
            else
            {
                throw new ArgumentException("Node is not an element or attribute: " + node.GetType(), nameof(node));
            }

            var parts = new List<XPathPart>();
            var ancestorsAndSelf = selectedElement.AncestorsAndSelf().Reverse();
            foreach(var ancestor in ancestorsAndSelf)
            {
                var part = new XPathPart();
                part.Node = ancestor;
                part.Predicates = ancestor.Attributes().Where(MatchesAnyFilter).ToArray();
                parts.Add(part);
            }
            if(IsAttribute(node))
            {
                parts.Add(new XPathPart {Node = node});
            }
            return parts;
        }
Ejemplo n.º 9
0
 private bool IsAttribute(XPathPart pathPart)
 {
     return(pathPart.Node is XAttribute);
 }
Ejemplo n.º 10
0
 private bool IsElement(XPathPart pathPart)
 {
     return(IsElement(pathPart.Node));
 }