protected override void WritePredicates(XPathPart pathPart) { WritePredicateStart(); XPath.Append(GetElementIndex((XElement)pathPart.Node)); WritePredicateEnd(); base.WritePredicates(pathPart); }
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); }
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; }
private bool IsAttribute(XPathPart pathPart) { return(pathPart.Node is XAttribute); }
private bool IsElement(XPathPart pathPart) { return(IsElement(pathPart.Node)); }