public override bool ParseXML(XPathNavigator node) { XPathNavigator child = node.Clone(); base.ParseXML(child); child = node.Clone(); if(child.MoveToChild("name", String.Empty)) name = child.Value; return true; }
public XPathNavigatorReader (XPathNavigator nav) { // It seems that this class have only to support linked // node as its parameter switch (nav.NodeType) { case XPathNodeType.Attribute: case XPathNodeType.Namespace: throw new InvalidOperationException (String.Format ("NodeType {0} is not supported to read as a subtree of an XPathNavigator.", nav.NodeType)); } root = nav.Clone (); current = nav.Clone (); }
public bool ParseXML(XPathNavigator node) { XPathNavigator child = node.Clone(); if(child.MoveToChild("id", String.Empty)) ID = child.ValueAsInt; child = node.Clone(); if(child.MoveToChild("code", String.Empty)) Code = child.Value; child = node.Clone(); if(child.MoveToChild("name", String.Empty)) Name = child.Value; return true; }
/// <summary> /// Creates a new instance of the <see cref="SchematronValidationEventArgs"/>. /// </summary> /// <param name="schematron">The <see cref="SchematronDocument"/> that detected the event.</param> /// <param name="queryEngine">The <see cref="IQueryLanguage"/> that detected the event.</param> /// <param name="pattern">The active <see cref="Pattern"/>.</param> /// <param name="rule">The <see cref="Sepia.Schematron.Rule"/> that caused the event to be raised.</param> /// <param name="assertion">The <see cref="Sepia.Schematron.Assertion"/> that caused the event to be raised.</param> /// <param name="context">An <see cref="object"/> that provides the context for the <paramref name="rule"/> and <paramref name="assertion"/>.</param> /// <param name="instance">An <see cref="XPathNavigator"/> to the document node that cause the event to be raised.</param> public SchematronValidationEventArgs(SchematronDocument schematron, IQueryLanguage queryEngine, Pattern pattern, Rule rule, Assertion assertion, object context, XPathNavigator instance) { this.schematron = schematron; this.queryEngine = queryEngine; this.pattern = pattern; this.rule = rule; this.assertion = assertion; this.instance = instance.Clone(); if (assertion == null) { message = "A schematron validation event occured."; } else { message = assertion.Message.ToString(instance, context); } List<string> diagnostics = new List<string>(); if (assertion != null && !string.IsNullOrEmpty(assertion.Diagnostics)) { foreach (string id in assertion.Diagnostics.Split(' ')) { Diagnostic diagnostic = schematron.Diagnostics[id]; diagnostics.Add(diagnostic.Message.ToString(instance, context)); } } this.diagnostics = diagnostics.ToArray(); }
public override XPathNavigator MatchNode(XPathNavigator context) { if (context != null) { if (!abbrAxis) { throw XPathException.Create(SR.Xp_InvalidPattern); } XPathNavigator result = null; if (matches(context)) { if (matchSelf) { if ((result = qyInput.MatchNode(context)) != null) { return result; } } XPathNavigator anc = context.Clone(); while (anc.MoveToParent()) { if ((result = qyInput.MatchNode(anc)) != null) { return result; } } } } return null; }
// get InnerXml without changing the spacing public static string GetInnerXml (XPathNavigator node) { // check for null argument, and clone so we don't change input if (node == null) throw new ArgumentNullException("node"); XPathNavigator current = node.Clone(); // create appropriate settings for the output writer XmlWriterSettings settings = new XmlWriterSettings(); settings.ConformanceLevel = ConformanceLevel.Fragment; settings.OmitXmlDeclaration = true; // construct a writer for our output StringBuilder builder = new StringBuilder(); XmlWriter writer = XmlWriter.Create(builder, settings); // write the output bool writing = current.MoveToFirstChild(); while (writing) { current.WriteSubtree(writer); writing = current.MoveToNext(); } // finish up and return the result writer.Close(); return(builder.ToString()); }
public XPathSimpleIterator(XPathBaseIterator parent) : base (parent) { this.parent = parent; navigator = parent.Current.Clone(); current = navigator.Clone(); pos = 0; }
public override XPathNavigator Advance() { while (true) { if (currentNode == null) { if (nextInput == null) { nextInput = FetchInput(); // This can happen at the begining and at the end } if (elementStk.Count == 0) { if (nextInput == null) { return null; } currentNode = nextInput; nextInput = FetchInput(); } else { currentNode = elementStk.Pop(); } } while (currentNode.IsDescendant(nextInput)) { elementStk.Push(currentNode); currentNode = nextInput; nextInput = qyInput.Advance(); if (nextInput != null) { nextInput = nextInput.Clone(); } } while (currentNode.MoveToNext()) { if (matches(currentNode)) { position++; return currentNode; } } currentNode = null; } } // Advance
void AddToStack(XPathNavigator current) { XmlNodeOrder compare; for (int i=0; i< ElementList.Count ; i++) { XPathNavigator nav = ElementList[i] as XPathNavigator; compare = nav.ComparePosition(current) ; if (compare == XmlNodeOrder.Same ) return; if (compare == XmlNodeOrder.Before) { ElementList.Insert(i,current.Clone()); return; } } ElementList.Add(current.Clone()); }
static public XPathNavigatorReader Create(XPathNavigator navToRead) { XPathNavigator nav = navToRead.Clone(); IXmlLineInfo xli = nav as IXmlLineInfo; IXmlSchemaInfo xsi = nav as IXmlSchemaInfo; #if NAVREADER_SUPPORTSLINEINFO if (null == xsi) { if (null == xli) { return new XPathNavigatorReader(nav, xli, xsi); } else { return new XPathNavigatorReaderWithLI(nav, xli, xsi); } } else { if (null == xli) { return new XPathNavigatorReaderWithSI(nav, xli, xsi); } else { return new XPathNavigatorReaderWithLIAndSI(nav, xli, xsi); } } #else if (null == xsi) { return new XPathNavigatorReader(nav, xli, xsi); } else { return new XPathNavigatorReaderWithSI(nav, xli, xsi); } #endif }
public override XPathNavigator MatchNode(XPathNavigator context) { if (context != null) { if (!this.abbrAxis) { throw XPathException.Create("Xp_InvalidPattern"); } XPathNavigator navigator = null; if (this.matches(context)) { if (this.matchSelf && ((navigator = base.qyInput.MatchNode(context)) != null)) { return navigator; } XPathNavigator current = context.Clone(); while (current.MoveToParent()) { navigator = base.qyInput.MatchNode(current); if (navigator != null) { return navigator; } } } } return null; }
static void FullName(XPathNavigator navigator, StringBuilder s) { if (navigator.NodeType == XPathNodeType.Root) return; string name = navigator.Name; string value = null; XPathNodeType nodeType = navigator.NodeType; if (nodeType == XPathNodeType.Attribute) value = navigator.Value; int same = 0; int position = 0; XPathNavigator sibling = navigator.Clone(); sibling.MoveToFirst(); do { if (sibling.NodeType == nodeType && sibling.Name == name) { if (sibling.IsSamePosition(navigator)) position = same; else ++same; } } while (sibling.MoveToNext()); if (navigator.MoveToParent()) FullName(navigator, s); switch (nodeType) { case XPathNodeType.Element: s.Append('/'); s.Append(name); if (same != 0) { s.Append('['); s.Append((position + 1).ToString(CultureInfo.InvariantCulture)); s.Append(']'); } break; case XPathNodeType.Attribute: s.Append("[@"); s.Append(name); if (same != 0) s.AppendFormat(" = '{0}'", value); s.Append("]"); break; case XPathNodeType.Comment: case XPathNodeType.Namespace: case XPathNodeType.ProcessingInstruction: case XPathNodeType.Root: case XPathNodeType.Text: case XPathNodeType.Whitespace: default: throw new NotSupportedException(); } }
private SubtreeeXPathNavigator(XPathNavigator root, XPathNavigator current, bool atRoot, bool enableFragment) { _root = root.Clone(); _navigator = current.Clone(); _atroot = atRoot; _fragment = enableFragment; }
public XPathSelectionIterator(XPathNavigator nav, XPathExpression expr) { this.nav = nav.Clone(); query = ((CompiledXpathExpr) expr).QueryTree; if (query.ReturnType() != XPathResultType.NodeSet) { throw new XPathException(Res.Xp_NodeSetExpected); } query.setContext(nav.Clone()); }
/// <summary> /// Adds a <see cref="XPathNavigator"/> to the set. /// </summary> /// <param name="navigator">The navigator to add. It's cloned automatically.</param> public void Add(XPathNavigator navigator) { if (_position != -1) throw new InvalidOperationException( SR.XPathNavigatorIterator_CantAddAfterMove); _navigators.Add(navigator.Clone()); }
protected static XPathNavigator Clone(XPathNavigator input) { if (input != null) { return input.Clone(); } return null; }
public XPathSelectionIterator(XPathNavigator nav, string xpath) { this.nav = nav; query = new QueryBuilder().Build( xpath, /*allowVar:*/true, /*allowKey:*/true ); if (query.ReturnType() != XPathResultType.NodeSet) { throw new XPathException(Res.Xp_NodeSetExpected); } query.setContext(nav.Clone()); }
public override object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext) { SeekableMessageNavigator navigator = docContext as SeekableMessageNavigator; if (navigator != null) { return navigator.Message.Version.Envelope.Namespace; } return ExtractFromNavigator(docContext.Clone()); }
public static string Translate(XPathNavigator descriptionNode, ReferenceLinkGeneratorDelegate refLinkGenerator) { // obtaining desc parent node var descParentNode = descriptionNode.Clone(); descParentNode.MoveToParent(); return ParseXML((XmlNode)descParentNode.UnderlyingObject, (XmlNode)descriptionNode.UnderlyingObject, refLinkGenerator); }
private bool NotVisited(XPathNavigator nav) { XPathNavigator nav1 = nav.Clone(); nav1.MoveToParent(); for(int i=0;i<_ParentStk.Count;i++) if (nav1.IsSamePosition((XPathNavigator)_ParentStk[i])) return false; _ParentStk.Add(nav1); return true; }
private void Parse(XPathNavigator eventElement) { XPathNavigator eventClone = eventElement.Clone(); eventElement.MoveToFirstAttribute(); type = CfgXmlHelper.ListenerTypeConvertFrom(eventElement.Value); XPathNodeIterator listenersI = eventClone.SelectDescendants(XPathNodeType.Element, false); while (listenersI.MoveNext()) { listeners.Add(new ListenerConfiguration(listenersI.Current, type)); } }
private bool NotVisited(XPathNavigator nav, List<XPathNavigator> parentStk){ XPathNavigator nav1 = nav.Clone(); nav1.MoveToParent(); for (int i = 0; i < parentStk.Count; i++) { if (nav1.IsSamePosition(parentStk[i])) { return false; } } parentStk.Add(nav1); return true; }
private bool Visited(XPathNavigator nav) { XPathNavigator parent = nav.Clone(); parent.MoveToParent(); for (int i = 0; i < parentStk.Count; i++) { if (parent.IsSamePosition(parentStk[i])) { return true; } } parentStk.Add(parent); return false; }
public static XPathNavigatorReader Create(XPathNavigator navToRead) { XPathNavigator navigator = navToRead.Clone(); IXmlLineInfo xli = navigator as IXmlLineInfo; IXmlSchemaInfo xsi = navigator as IXmlSchemaInfo; if (xsi == null) { return new XPathNavigatorReader(navigator, xli, xsi); } return new XPathNavigatorReaderWithSI(navigator, xli, xsi); }
public override XPathNavigator MatchNode(XPathNavigator context) { if (context != null) { if (context.NodeType == XPathNodeType.Attribute && matches(context)) { XPathNavigator temp = context.Clone(); if (temp.MoveToParent()) { return qyInput.MatchNode(temp); } } } return null; }
public sealed override XPathNavigator MatchNode(XPathNavigator context) { if ((context != null) && this.matches(context)) { XPathNavigator current = context.Clone(); if ((current.NodeType != XPathNodeType.Attribute) && current.MoveToParent()) { return base.qyInput.MatchNode(current); } } return null; }
public override bool ParseXML(XPathNavigator node) { XPathNavigator child = node.Clone(); base.ParseXML(child); if(child.MoveToChild("architecture", String.Empty)) arch.ParseXML(child); child = node.Clone(); if(child.MoveToChild("content-type", String.Empty)) contentType = child.Value; child = node.Clone(); if(child.MoveToChild("filename", String.Empty)) filename = child.Value; child = node.Clone(); if(child.MoveToChild("size", String.Empty)) size = child.ValueAsInt; return true; }
public override XPathNavigator Advance() { if (_iterator == null) { _input = qyInput.Advance(); if (_input == null) { return null; } XPathNavigator prev; do { prev = _input.Clone(); _input = qyInput.Advance(); } while (prev.IsDescendant(_input)); _input = prev; _iterator = XPathEmptyIterator.Instance; } while (!_iterator.MoveNext()) { bool matchSelf; if (_input.NodeType == XPathNodeType.Attribute || _input.NodeType == XPathNodeType.Namespace) { _input.MoveToParent(); matchSelf = false; } else { while (!_input.MoveToNext()) { if (!_input.MoveToParent()) { return null; } } matchSelf = true; } if (NameTest) { _iterator = _input.SelectDescendants(Name, Namespace, matchSelf); } else { _iterator = _input.SelectDescendants(TypeTest, matchSelf); } } position++; currentNode = _iterator.Current; return currentNode; }
public XPathNavigatorReader(XPathNavigator nav) : base(new StringReader("")) { switch (nav.NodeType) { case XPathNodeType.Element: case XPathNodeType.Root: break; default: throw new InvalidOperationException(String.Format("NodeType {0} is not supported to read as a subtree of an XPathNavigator.", nav.NodeType)); } current = nav.Clone(); }
/// <summary> /// WebDav Property. /// </summary> /// <param name="property"></param> public DavProperty(XPathNavigator property) { if (property == null) throw new ArgumentNullException("property", InternalFunctions.GetResourceString("ArgumentNullException", "Property")); else if (property.NodeType != XPathNodeType.Element) throw new ArgumentException(InternalFunctions.GetResourceString("XPathNavigatorElementArgumentException", "Property"), "property"); base.Name = property.LocalName; base.Namespace = property.NamespaceURI; if (property.HasAttributes) { //TODO: Support element attributes //string _here = ""; //Add the attributes first // foreach (XmlAttribute _xmlAttribute in property.Attributes) // Attributes.Add(new DavPropertyAttribute(_xmlAttribute)); } if (property.MoveToFirstChild()) { if (property.NodeType == XPathNodeType.Element) { NestedProperties.Add(new DavProperty(property.Clone())); while (property.MoveToNext()) { if (property.NodeType == XPathNodeType.Element) NestedProperties.Add(new DavProperty(property.Clone())); } } else if (property.NodeType == XPathNodeType.Text) { base.Value = property.Value; property.MoveToParent(); } } }
public override ResetableIterator MakeNewCopy() { return(new XPathSelectionIterator(nav.Clone(), query.Clone())); }
static public XPathNavigatorReader Create(XPathNavigator navToRead) { XPathNavigator nav = navToRead.Clone(); return(new XPathNavigatorReader(nav)); }
public override string GetAttribute(string name) { string str; string str2; XPathNavigator nav = this.nav; switch (nav.NodeType) { case XPathNodeType.Element: break; case XPathNodeType.Attribute: nav = nav.Clone(); if (nav.MoveToParent()) { break; } return(null); default: return(null); } ValidateNames.SplitQName(name, out str, out str2); if (str.Length == 0) { if (str2 == "xmlns") { return(nav.GetNamespace(string.Empty)); } if (nav == this.nav) { nav = nav.Clone(); } if (nav.MoveToAttribute(str2, string.Empty)) { return(nav.Value); } } else { if (str == "xmlns") { return(nav.GetNamespace(str2)); } if (nav == this.nav) { nav = nav.Clone(); } if (nav.MoveToFirstAttribute()) { do { if ((nav.LocalName == str2) && (nav.Prefix == str)) { return(nav.Value); } }while (nav.MoveToNextAttribute()); } } return(null); }
public virtual XmlNodeOrder ComparePosition(XPathNavigator nav) { if (IsSamePosition(nav)) { return(XmlNodeOrder.Same); } // quick check for direct descendant if (IsDescendant(nav)) { return(XmlNodeOrder.Before); } // quick check for direct ancestor if (nav.IsDescendant(this)) { return(XmlNodeOrder.After); } XPathNavigator nav1 = Clone(); XPathNavigator nav2 = nav.Clone(); // check if document instance is the same. nav1.MoveToRoot(); nav2.MoveToRoot(); if (!nav1.IsSamePosition(nav2)) { return(XmlNodeOrder.Unknown); } nav1.MoveTo(this); nav2.MoveTo(nav); int depth1 = 0; while (nav1.MoveToParent()) { depth1++; } nav1.MoveTo(this); int depth2 = 0; while (nav2.MoveToParent()) { depth2++; } nav2.MoveTo(nav); // find common parent depth int common = depth1; for (; common > depth2; common--) { nav1.MoveToParent(); } for (int i = depth2; i > common; i--) { nav2.MoveToParent(); } while (!nav1.IsSamePosition(nav2)) { nav1.MoveToParent(); nav2.MoveToParent(); common--; } // For each this and target, move to the node that is // ancestor of the node and child of the common parent. nav1.MoveTo(this); for (int i = depth1; i > common + 1; i--) { nav1.MoveToParent(); } nav2.MoveTo(nav); for (int i = depth2; i > common + 1; i--) { nav2.MoveToParent(); } // Those children of common parent are comparable. // namespace nodes precede to attributes, and they // precede to other nodes. if (nav1.NodeType == XPathNodeType.Namespace) { if (nav2.NodeType != XPathNodeType.Namespace) { return(XmlNodeOrder.Before); } while (nav1.MoveToNextNamespace()) { if (nav1.IsSamePosition(nav2)) { return(XmlNodeOrder.Before); } } return(XmlNodeOrder.After); } if (nav2.NodeType == XPathNodeType.Namespace) { return(XmlNodeOrder.After); } if (nav1.NodeType == XPathNodeType.Attribute) { if (nav2.NodeType != XPathNodeType.Attribute) { return(XmlNodeOrder.Before); } while (nav1.MoveToNextAttribute()) { if (nav1.IsSamePosition(nav2)) { return(XmlNodeOrder.Before); } } return(XmlNodeOrder.After); } while (nav1.MoveToNext()) { if (nav1.IsSamePosition(nav2)) { return(XmlNodeOrder.Before); } } return(XmlNodeOrder.After); }
public override ResetableIterator MakeNewCopy() { return(new XPathQueryIterator(query.Clone(), nav.Clone())); }
public virtual XmlNodeOrder ComparePosition(XPathNavigator nav) { if (IsSamePosition(nav)) { return(XmlNodeOrder.Same); } if (IsDescendant(nav)) { return(XmlNodeOrder.Before); } else if (nav.IsDescendant(this)) { return(XmlNodeOrder.After); } XPathNavigator copy = this.Clone(); XPathNavigator other = nav.Clone(); /* now, it gets expensive - we find the * closest common ancestor. But these two * might be from totally different places. * * Someone should re-implement this somewhere, * so that it is faster for XmlDocument. */ int common = 0; int otherDepth = 0; int copyDepth = 0; copy.MoveToRoot(); other.MoveToRoot(); if (!copy.IsSamePosition(other)) { return(XmlNodeOrder.Unknown); } /* what do you think ? I'm made of GC space ? */ copy.MoveTo(this); other.MoveTo(nav); while (other.MoveToParent()) { otherDepth++; } while (copy.MoveToParent()) { copyDepth++; } common = (otherDepth > copyDepth) ? copyDepth : otherDepth; other.MoveTo(nav); copy.MoveTo(this); // traverse both till you get to depth == common for (; otherDepth > common; otherDepth--) { other.MoveToParent(); } for (; copyDepth > common; copyDepth--) { copy.MoveToParent(); } other.MoveTo(nav); copy.MoveTo(this); XPathNavigator copy1 = copy.Clone(); XPathNavigator other1 = other.Clone(); while (copy.IsSamePosition(other)) { copy1.MoveTo(copy); other1.MoveTo(other); copy.MoveToParent(); other.MoveToParent(); } copy.MoveTo(copy1); other.MoveTo(other1); // Now copy & other are siblings and can be compared while (copy.MoveToNext()) { if (copy.IsSamePosition(other)) { return(XmlNodeOrder.Before); } } return(XmlNodeOrder.After); }
internal override void setContext(XPathNavigator e) { reset(); qy1.setContext(e.Clone()); qy2.setContext(e.Clone()); }
internal override void setContext(XPathNavigator context) { reset(); base.setContext(context); _context = context.Clone(); }
public override bool MoveToNextAttribute() { switch (this.state) { case State.Content: return(this.MoveToFirstAttribute()); case State.Attribute: if (XPathNodeType.Attribute != this.nav.NodeType) { XPathNavigator other = this.nav.Clone(); if (other.MoveToParent()) { if (!other.MoveToFirstNamespace(XPathNamespaceScope.Local)) { return(false); } if (other.IsSamePosition(this.nav)) { other.MoveToParent(); if (!other.MoveToFirstAttribute()) { return(false); } this.nav.MoveTo(other); return(true); } XPathNavigator navigator2 = other.Clone(); while (other.MoveToNextNamespace(XPathNamespaceScope.Local)) { if (other.IsSamePosition(this.nav)) { this.nav.MoveTo(navigator2); return(true); } navigator2.MoveTo(other); } } return(false); } return(this.nav.MoveToNextAttribute()); case State.AttrVal: this.depth--; this.state = State.Attribute; if (this.MoveToNextAttribute()) { break; } this.depth++; this.state = State.AttrVal; return(false); case State.InReadBinary: this.state = this.savedState; if (this.MoveToNextAttribute()) { this.readBinaryHelper.Finish(); return(true); } this.state = State.InReadBinary; return(false); default: return(false); } this.nodeType = XmlNodeType.Attribute; return(true); }
public SimpleIterator(XPathNavigator nav, NSResolver nsm) : base(nsm) { _nav = nav.Clone(); }
internal override XPathNavigator advance() { if (_eLast == null) { XPathNavigator temp = null; _eLast = m_qyInput.advance(); if (_eLast == null) { return(null); } while (_eLast != null) { _eLast = _eLast.Clone(); temp = _eLast; _eLast = m_qyInput.advance(); if (!temp.IsDescendant(_eLast)) { break; } } _eLast = temp; } while (true) { if (_first) { _first = false; if (_eLast.NodeType == XPathNodeType.Attribute || _eLast.NodeType == XPathNodeType.Namespace) { _eLast.MoveToParent(); if (_fMatchName) { _qy = _eLast.SelectDescendants(m_Name, m_URN, false); } else { _qy = _eLast.SelectDescendants(m_Type, false); } } else { while (true) { if (!_eLast.MoveToNext()) { if (!_eLast.MoveToParent()) { _first = true; return(null); } } else { break; } } if (_fMatchName) { _qy = _eLast.SelectDescendants(m_Name, m_URN, true); } else { _qy = _eLast.SelectDescendants(m_Type, true); } } } if (_qy.MoveNext()) { _position++; m_eNext = _qy.Current; return(m_eNext); } else { _first = true; } } }
private void InvokeFunction(XPathNavigator qy) { IXsltContextFunction function = this.Function; // calculate arguments: Debug.Assert(_ArgArray != null && _ArgArray.Length == _ArgList.Count); for (int i = _ArgList.Count - 1; 0 <= i; i--) { IQuery arg = (IQuery)_ArgList[i]; if (arg.ReturnType() == XPathResultType.NodeSet) { _ArgArray[i] = new XPathQueryIterator(arg, qy.Clone()); } else { _ArgArray[i] = arg.getValue(qy, null); } } try { object result = function.Invoke(_XsltContext, _ArgArray, qy); if (result == null) { _ResultQuery = new OperandQuery(String.Empty, XPathResultType.String); } else { XPathResultType returnedType = function.ReturnType; if (returnedType == XPathResultType.Any) { // If function is untyped get returned type from real result returnedType = XsltCompileContext.GetXPathType(result.GetType()); } switch (returnedType) { case XPathResultType.String: // trick. As soon XPathResultType.Navigator will be distinct type rid of from it. //_ResultQuery = new OperandQuery( result, XPathResultType.String ); if (result is XPathNavigator) { _ResultQuery = new NavigatorQuery((XPathNavigator)result); } else { _ResultQuery = new OperandQuery(result, XPathResultType.String); } break; case XPathResultType.Boolean: _ResultQuery = new OperandQuery(result, XPathResultType.Boolean); break; case XPathResultType.Number: _ResultQuery = new OperandQuery(XmlConvert.ToXPathDouble(result), XPathResultType.Number); break; case XPathResultType.NodeSet: if (result is ResetableIterator) { _ResultQuery = new XmlIteratorQuery((ResetableIterator)result); } else { Debug.Assert(false, "Unexpected type of XPathNodeIterator"); throw new NotSupportedException(Res.GetString(Res.XmlUnsupportedType, result.GetType().FullName)); } break; // case XPathResultType.Navigator : // _ResultQuery = new NavigatorQuery((XPathNavigator)result); // break; default: _ResultQuery = new OperandQuery(result.ToString(), XPathResultType.String); break; } } } catch (Exception ex) { string qname = _Prefix != string.Empty ? _Prefix + ":" + _Name : _Name; throw new XsltException(Res.Xslt_FunctionFailed, new string[] { qname }, ex); } }
protected XPathNavigator MatchNode(XPathNavigator current, IQuery query) { XPathNavigator context; if (current != null) { context = query.MatchNode(current); if (context != null) { if (_opnd.ReturnType() == XPathResultType.Number) { if (_opnd.getName() == Querytype.Constant) { XPathNavigator result = current.Clone(); int i = 0; if (query.getName() == Querytype.Child) { result.MoveToParent(); result.MoveToFirstChild(); while (true) { if (((ChildrenQuery)query).matches(result)) { i++; if (current.IsSamePosition(result)) { if (XmlConvert.ToXPathDouble(_opnd.getValue(current, null)) == i) { return(context); } else { return(null); } } } if (!result.MoveToNext()) { return(null); } } } if (query.getName() == Querytype.Attribute) { result.MoveToParent(); result.MoveToFirstAttribute(); while (true) { if (((AttributeQuery)query).matches(result)) { i++; } if (current.IsSamePosition(result)) { if (XmlConvert.ToXPathDouble(_opnd.getValue(current, null)) == i) { return(context); } else { return(null); } } if (!result.MoveToNextAttribute()) { return(null); } } } } else { setContext(context.Clone()); XPathNavigator result = advance(); while (result != null) { if (result.IsSamePosition(current)) { return(context); } result = advance(); } } } if (_opnd.ReturnType() == XPathResultType.NodeSet) { _opnd.setContext(current); if (_opnd.advance() != null) { return(context); } else { return(null); } } if (_opnd.ReturnType() == XPathResultType.Boolean) { if (noPosition) { if ((bool)_opnd.getValue(current, null)) { return(context); } return(null); } setContext(context.Clone()); XPathNavigator result = advance(); while (result != null) { if (result.IsSamePosition(current)) { return(context); } result = advance(); } return(null); } if (_opnd.ReturnType() == XPathResultType.String) { if (_opnd.getValue(context, null).ToString().Length > 0) { return(context); } else { return(null); } } } else { return(null); } } return(null); }
internal override XPathNavigator advance() { while (true) { if (m_eNext == null) { if (_ElementStk.Count == 0) { if (_NextInput == null) { while ((m_eNext = m_qyInput.advance()) != null) { if (NotVisited(m_eNext)) { break; } } if (m_eNext != null) { m_eNext = m_eNext.Clone(); } else { return(null); } } else { m_eNext = _NextInput; _NextInput = null; } } else { m_eNext = _ElementStk.Pop() as XPathNavigator; } } if (_NextInput == null) { while ((_NextInput = m_qyInput.advance()) != null) { if (NotVisited(_NextInput)) { break; } } if (_NextInput != null) { _NextInput = _NextInput.Clone(); } } if (_NextInput != null) { while (m_eNext.IsDescendant(_NextInput)) { _ElementStk.Push(m_eNext); m_eNext = _NextInput; _NextInput = m_qyInput.advance(); if (_NextInput != null) { _NextInput = _NextInput.Clone(); } } } while (m_eNext.MoveToNext()) { if (matches(m_eNext)) { _position++; return(m_eNext); } } m_eNext = null; } //return null; } // Advance
public SimpleIterator(XPathNavigator nav, IXmlNamespaceResolver nsm) : base(nsm) { this._nav = nav.Clone(); }
public override string GetAttribute(string name) { // reader allows calling GetAttribute, even when positioned inside attributes XPathNavigator nav = _nav; switch (nav.NodeType) { case XPathNodeType.Element: break; case XPathNodeType.Attribute: nav = nav.Clone(); if (!nav.MoveToParent()) { return(null); } break; default: return(null); } string prefix, localname; ValidateNames.SplitQName(name, out prefix, out localname); if (0 == prefix.Length) { if (localname == "xmlns") { return(nav.GetNamespace(string.Empty)); } if ((object)nav == (object)_nav) { nav = nav.Clone(); } if (nav.MoveToAttribute(localname, string.Empty)) { return(nav.Value); } } else { if (prefix == "xmlns") { return(nav.GetNamespace(localname)); } if ((object)nav == (object)_nav) { nav = nav.Clone(); } if (nav.MoveToFirstAttribute()) { do { if (nav.LocalName == localname && nav.Prefix == prefix) { return(nav.Value); } } while (nav.MoveToNextAttribute()); } } return(null); }
/// <summary>See <see cref="IMatchedNodes.AddMatched"/>.</summary> public void AddMatched(System.Xml.XPath.XPathNavigator node) { _matched.Add(node.Clone()); }
public override bool MoveToNextAttribute() { switch (_state) { case State.Content: return(MoveToFirstAttribute()); case State.Attribute: { if (XPathNodeType.Attribute == _nav.NodeType) { return(_nav.MoveToNextAttribute()); } // otherwise it is on a namespace... namespace are in reverse order Debug.Assert(XPathNodeType.Namespace == _nav.NodeType); XPathNavigator nav = _nav.Clone(); if (!nav.MoveToParent()) { return(false); // shouldn't happen } if (!nav.MoveToFirstNamespace(XPathNamespaceScope.Local)) { return(false); // shouldn't happen } if (nav.IsSamePosition(_nav)) { // this was the last one... start walking attributes nav.MoveToParent(); if (!nav.MoveToFirstAttribute()) { return(false); } // otherwise we are there _nav.MoveTo(nav); return(true); } else { XPathNavigator prev = nav.Clone(); for (; ;) { if (!nav.MoveToNextNamespace(XPathNamespaceScope.Local)) { Debug.Fail("Couldn't find Namespace Node! Should not happen!"); return(false); } if (nav.IsSamePosition(_nav)) { _nav.MoveTo(prev); return(true); } prev.MoveTo(nav); } // found previous namespace position } } case State.AttrVal: _depth--; _state = State.Attribute; if (!MoveToNextAttribute()) { _depth++; _state = State.AttrVal; return(false); } _nodeType = XmlNodeType.Attribute; return(true); case State.InReadBinary: _state = _savedState; if (!MoveToNextAttribute()) { _state = State.InReadBinary; return(false); } _readBinaryHelper.Finish(); return(true); default: return(false); } }
internal override XPathNavigator advance() { switch (m_qyInput.ReturnType()) { case XPathResultType.NodeSet: if (ElementList == null) { ElementList = new ArrayList(); XPathNavigator temp; while ((temp = m_qyInput.advance()) != null) { if (_context.MoveToId(temp.Value)) { AddToStack(_context.Clone()); } } strcount = ElementList.Count; } Debug.Assert(strcount >= 0); if (strcount != 0) { return(ElementList[--strcount] as XPathNavigator); } return(null); case XPathResultType.String: if (ElementList == null) { String str = (String)m_qyInput.getValue(_context, null); char[] a = { ' ' }; String[] strarray = str.Split(null); ElementList = new ArrayList(); while (strcount < strarray.Length) { if (_context.MoveToId(strarray[strcount++])) { AddToStack(_context.Clone()); } } strcount = ElementList.Count; } Debug.Assert(strcount >= 0); if (strcount != 0) { return(ElementList[--strcount] as XPathNavigator); } return(null); case XPathResultType.Number: if (strcount == 0 && _context.MoveToId(StringFunctions.toString((double)m_qyInput.getValue(_context, null)))) { strcount = 1; return(_context); } else { return(null); } case XPathResultType.Boolean: if (strcount == 0 && _context.MoveToId(StringFunctions.toString((Boolean)m_qyInput.getValue(_context, null)))) { strcount = 1; return(_context); } else { return(null); } } return(null); } // Advance
internal override object getValue(XPathNavigator qyContext, XPathNodeIterator iterator) { XPathNavigator eNext; switch (_FType) { case FT.FuncPosition: if (iterator != null) { return((double)iterator.CurrentPosition); } return((double)0); case FT.FuncNameSpaceUri: if (_Opnd != null) { _Opnd.setContext(qyContext.Clone()); if ((eNext = _Opnd.advance()) != null) { return(eNext.NamespaceURI); } else { return(String.Empty); } } if (qyContext != null) { return(qyContext.NamespaceURI); } return(String.Empty); case FT.FuncLocalName: if (_Opnd != null) { _Opnd.setContext(qyContext.Clone()); if ((eNext = _Opnd.advance()) != null) { return(eNext.LocalName); } else { return(String.Empty); } } if (qyContext != null) { return(qyContext.LocalName); } return(String.Empty); case FT.FuncName: if (_Opnd != null) { _Opnd.setContext(qyContext.Clone()); if ((eNext = _Opnd.advance()) != null) { return(eNext.Name); } else { return(String.Empty); } } if (qyContext != null) { return(qyContext.Name); } return(String.Empty); case FT.FuncCount: int i = 0; _Opnd.setContext(qyContext.Clone()); if (checkWhitespace) { XPathNavigator nav; while ((nav = _Opnd.advance()) != null) { if (nav.NodeType != XPathNodeType.Whitespace || context.PreserveWhitespace(nav)) { i++; } } return((double)i); } while (_Opnd.advance() != null) { i++; } return((double)i); case FT.FuncLast: if (iterator != null) { return((double)iterator.Count); } else { return((double)0); } } return(String.Empty); }
public static void WriteNode(this XmlWriter writer, XPathNavigator navigator, bool defattr) { if (navigator == null) { throw new ArgumentNullException("navigator"); } int iLevel = 0; navigator = navigator.Clone(); while (true) { bool mayHaveChildren = false; XPathNodeType nodeType = navigator.NodeType; switch (nodeType) { case XPathNodeType.Element: writer.WriteStartElement(navigator.Prefix, navigator.LocalName, navigator.NamespaceURI); // Copy attributes if (navigator.MoveToFirstAttribute()) { do { writer.WriteStartAttribute(navigator.Prefix, navigator.LocalName, navigator.NamespaceURI); // copy string value to writer writer.WriteString(navigator.Value); writer.WriteEndAttribute(); } while (navigator.MoveToNextAttribute()); navigator.MoveToParent(); } // Copy namespaces if (navigator.MoveToFirstNamespace(XPathNamespaceScope.Local)) { writer.WriteLocalNamespaces(navigator); navigator.MoveToParent(); } mayHaveChildren = true; break; case XPathNodeType.Attribute: // do nothing on root level attribute break; case XPathNodeType.Text: writer.WriteString(navigator.Value); break; case XPathNodeType.SignificantWhitespace: case XPathNodeType.Whitespace: writer.WriteWhitespace(navigator.Value); break; case XPathNodeType.Root: mayHaveChildren = true; break; case XPathNodeType.Comment: writer.WriteComment(navigator.Value); break; case XPathNodeType.ProcessingInstruction: writer.WriteProcessingInstruction(navigator.LocalName, navigator.Value); break; case XPathNodeType.Namespace: // do nothing on root level namespace break; default: Debug.Assert(false); break; } if (mayHaveChildren) { // If children exist, move down to next level if (navigator.MoveToFirstChild()) { iLevel++; continue; } else { // EndElement if (navigator.NodeType == XPathNodeType.Element) { if (navigator.IsEmptyElement) { writer.WriteEndElement(); } else { writer.WriteFullEndElement(); } } } } // No children while (true) { if (iLevel == 0) { // The entire subtree has been copied return; } if (navigator.MoveToNext()) { // Found a sibling, so break to outer loop break; } // No siblings, so move up to previous level iLevel--; navigator.MoveToParent(); // EndElement if (navigator.NodeType == XPathNodeType.Element) { writer.WriteFullEndElement(); } } } }