internal override void setContext(XPathNavigator e) { Debug.Assert(e != null); e = e.Clone(); e.MoveToRoot(); base.setContext(e); }
protected virtual void OnMovingToRootItem(XPathNavigator navigator) { navigator.MoveToRoot(); if (!navigator.MoveToFirstChild()) throw new InvalidXmlException("Expected node n2 not found"); if (!navigator.MoveToFirstChild()) throw new InvalidXmlException("Expected node item not found"); }
internal override XPathNavigator advance() { if (proceed) { if (temp == null) { XPathNavigator _eLast = m_qyInput.advance(); while (_eLast != null) { temp = _eLast.Clone(); _eLast = m_qyInput.advance(); } if (temp == null || temp.NodeType == XPathNodeType.Root) { return(null); } if (temp.NodeType == XPathNodeType.Attribute || temp.NodeType == XPathNodeType.Namespace) { temp.MoveToParent(); } NotVisited(temp.Clone()); _AncestorStk.Add(temp.Clone()); temp.MoveToRoot(); _qy = temp.SelectDescendants(XPathNodeType.All, false); } int flag; while (_qy.MoveNext()) { m_eNext = _qy.Current; if (matches(m_eNext)) { flag = InStk(m_eNext); if (flag == 1) { _position++; return(m_eNext); } if (flag == 2) { proceed = false; m_eNext = null; return(null); } } else { if (m_eNext.IsSamePosition((XPathNavigator)_AncestorStk[_AncestorStk.Count - 1])) { proceed = false; m_eNext = null; return(null); } } } return(null); } return(null); }
public override object Evaluate(BaseIterator iter) { if (iter.CurrentPosition == 0) { iter = (BaseIterator)iter.Clone(); iter.MoveNext(); } XPathNavigator xpathNavigator = iter.Current.Clone(); xpathNavigator.MoveToRoot(); return(new SelfIterator(xpathNavigator, iter.NamespaceManager)); }
internal static string ExtractFromNavigator(XPathNavigator nav) { nav.MoveToRoot(); if (nav.MoveToFirstChild()) { string namespaceURI = nav.NamespaceURI; if (!(nav.LocalName != "Envelope") && (!(namespaceURI != "http://schemas.xmlsoap.org/soap/envelope/") || !(namespaceURI != "http://www.w3.org/2003/05/soap-envelope"))) { return namespaceURI; } } return string.Empty; }
internal static string ExtractFromNavigator(XPathNavigator nav) { string attribute = nav.GetAttribute(XPathMessageContext.Actor11A, "http://schemas.xmlsoap.org/soap/envelope/"); string str2 = nav.GetAttribute(XPathMessageContext.Actor12A, "http://www.w3.org/2003/05/soap-envelope"); nav.MoveToRoot(); nav.MoveToFirstChild(); if ((nav.LocalName == "Envelope") && (nav.NamespaceURI == "http://schemas.xmlsoap.org/soap/envelope/")) { return attribute; } if ((nav.LocalName == "Envelope") && (nav.NamespaceURI == "http://www.w3.org/2003/05/soap-envelope")) { return str2; } return string.Empty; }
internal static bool ExtractFromNavigator(XPathNavigator nav) { string str = XPathMessageFunctionActor.ExtractFromNavigator(nav); nav.MoveToRoot(); if (nav.MoveToFirstChild() && (nav.LocalName == "Envelope")) { if (nav.NamespaceURI == "http://schemas.xmlsoap.org/soap/envelope/") { return (str == S11UltRec); } if (nav.NamespaceURI == "http://www.w3.org/2003/05/soap-envelope") { return (str == S12UltRec); } } return false; }
public void ReadSubtree1 () { string xml = "<root/>"; nav = GetXmlDocumentNavigator (xml); ReadSubtree1 (nav, "#1."); nav.MoveToRoot (); nav.MoveToFirstChild (); ReadSubtree1 (nav, "#2."); nav = GetXPathDocumentNavigator (document); ReadSubtree1 (nav, "#3."); nav.MoveToRoot (); nav.MoveToFirstChild (); ReadSubtree1 (nav, "#4."); }
internal static bool MoveToBody(XPathNavigator nav) { nav.MoveToRoot(); if (nav.MoveToFirstChild()) { string namespaceURI = nav.NamespaceURI; if ((nav.LocalName != "Envelope") || ((namespaceURI != "http://schemas.xmlsoap.org/soap/envelope/") && (namespaceURI != "http://www.w3.org/2003/05/soap-envelope"))) { return false; } if (nav.MoveToFirstChild()) { do { if ((nav.LocalName == "Body") && (nav.NamespaceURI == namespaceURI)) { return true; } } while (nav.MoveToNext()); } } return false; }
internal static bool ExtractFromNavigator(XPathNavigator nav) { string mand11 = nav.GetAttribute(XPathMessageContext.MandatoryA, XPathMessageContext.S11NS); string mand12 = nav.GetAttribute(XPathMessageContext.MandatoryA, XPathMessageContext.S12NS); nav.MoveToRoot(); nav.MoveToFirstChild(); if (nav.LocalName == XPathMessageContext.EnvelopeE && nav.NamespaceURI == XPathMessageContext.S11NS) { return mand11 == "1"; } else if (nav.LocalName == XPathMessageContext.EnvelopeE && nav.NamespaceURI == XPathMessageContext.S12NS) { return mand12 == "true"; } return false; }
internal override void setContext( XPathNavigator e) { Debug.Assert(e != null); e = e.Clone(); e.MoveToRoot(); base.setContext( e); }
/// <summary> /// Parses an XML document for its namespaces. /// </summary> /// <param name="navigator">The navigator.</param> public void ParseNamespaces(XPathNavigator navigator) { if (navigator == null) throw new ArgumentNullException("navigator"); if (Namespaces == null) Namespaces = new Dictionary<string, string>(); if (String.IsNullOrEmpty(DefaultPrefix)) DefaultPrefix = "d"; DefaultNamespaces.Clear(); navigator.MoveToRoot(); RrecursiveParse(navigator); //add default namespaces int defaultIndex = 0; foreach (string name in DefaultNamespaces) { string key = GetDefaultKey(defaultIndex++); Namespaces.Add(key, name); } }
private void XmlNamespaceNode (XPathNavigator nav) { string xhtml = "http://www.w3.org/1999/xhtml"; string xmlNS = "http://www.w3.org/XML/1998/namespace"; nav.MoveToFirstChild (); AssertNavigator ("#1", nav, XPathNodeType.Element, "", "html", xhtml, "html", "test.", false, true, false); Assert.IsTrue (nav.MoveToFirstNamespace (XPathNamespaceScope.Local)); AssertNavigator ("#2", nav, XPathNodeType.Namespace, "", "", "", "", xhtml, false, false, false); // Test difference between Local, ExcludeXml and All. Assert.IsTrue (!nav.MoveToNextNamespace (XPathNamespaceScope.Local)); Assert.IsTrue (!nav.MoveToNextNamespace (XPathNamespaceScope.ExcludeXml)); // LAMESPEC: MS.NET 1.0 XmlDocument seems to have some bugs around here. // see http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q316808 #if true Assert.IsTrue (nav.MoveToNextNamespace (XPathNamespaceScope.All)); AssertNavigator ("#3", nav, XPathNodeType.Namespace, "", "xml", "", "xml", xmlNS, false, false, false); Assert.IsTrue (!nav.MoveToNextNamespace (XPathNamespaceScope.All)); #endif // Test to check if MoveToRoot() resets Namespace node status. nav.MoveToRoot (); AssertNavigator ("#4", nav, XPathNodeType.Root, "", "", "", "", "test.", false, true, false); nav.MoveToFirstChild (); // Test without XPathNamespaceScope argument. Assert.IsTrue (nav.MoveToFirstNamespace ()); Assert.IsTrue (nav.MoveToNextNamespace ()); AssertNavigator ("#5", nav, XPathNodeType.Namespace, "", "xml", "", "xml", xmlNS, false, false, false); // Test MoveToParent() Assert.IsTrue (nav.MoveToParent ()); AssertNavigator ("#6", nav, XPathNodeType.Element, "", "html", xhtml, "html", "test.", false, true, false); nav.MoveToFirstChild (); // body // Test difference between Local and ExcludeXml Assert.IsTrue (!nav.MoveToFirstNamespace (XPathNamespaceScope.Local), "Local should fail"); Assert.IsTrue (nav.MoveToFirstNamespace (XPathNamespaceScope.ExcludeXml), "ExcludeXml should succeed"); AssertNavigator ("#7", nav, XPathNodeType.Namespace, "", "", "", "", xhtml, false, false, false); Assert.IsTrue (nav.MoveToNextNamespace (XPathNamespaceScope.All)); AssertNavigator ("#8", nav, XPathNodeType.Namespace, "", "xml", "", "xml", xmlNS, false, false, false); Assert.IsTrue (nav.MoveToParent ()); AssertNavigator ("#9", nav, XPathNodeType.Element, "", "body", xhtml, "body", "test.", false, true, false); nav.MoveToRoot (); AssertNavigator ("#10", nav, XPathNodeType.Root, "", "", "", "", "test.", false, true, false); }
private void XmlTwoElementsContent (XPathNavigator nav) { AssertNavigator ("#1", nav, XPathNodeType.Root, "", "", "", "", "", false, true, false); Assert.IsTrue (nav.MoveToFirstChild ()); AssertNavigator ("#2", nav, XPathNodeType.Element, "", "foo", "", "foo", "", false, true, false); Assert.IsTrue (!nav.MoveToNext ()); Assert.IsTrue (!nav.MoveToPrevious ()); Assert.IsTrue (nav.MoveToFirstChild ()); AssertNavigator ("#3", nav, XPathNodeType.Element, "", "bar", "", "bar", "", false, false, true); Assert.IsTrue (!nav.MoveToFirstChild ()); Assert.IsTrue (nav.MoveToNext ()); AssertNavigator ("#4", nav, XPathNodeType.Element, "", "baz", "", "baz", "", false, false, true); Assert.IsTrue (!nav.MoveToFirstChild ()); Assert.IsTrue (nav.MoveToPrevious ()); AssertNavigator ("#5", nav, XPathNodeType.Element, "", "bar", "", "bar", "", false, false, true); nav.MoveToRoot (); AssertNavigator ("#6", nav, XPathNodeType.Root, "", "", "", "", "", false, true, false); Assert.IsTrue (!nav.MoveToNext ()); }
public void ElementAndRootValues() { document.LoadXml ("<foo><bar>baz</bar><quux>quuux</quux></foo>"); navigator = document.DocumentElement.CreateNavigator (); Assert.AreEqual (XPathNodeType.Element, navigator.NodeType, "#1"); Assert.AreEqual ("foo", navigator.Name, "#2"); //Assert.AreEqual ("bazquuux", navigator.Value, "#3"); navigator.MoveToRoot (); //Assert.AreEqual ("bazquuux", navigator.Value, "#4"); }
public void DocElem_OpenClose_Attribute () { string xml = "<root attr='value'></root>"; nav = GetXmlDocumentNavigator (xml); DocElem_OpenClose_Attribute (nav, "#1."); nav.MoveToRoot (); nav.MoveToFirstChild (); DocElem_OpenClose_Attribute (nav, "#2."); nav = GetXPathDocumentNavigator (document); DocElem_OpenClose_Attribute (nav, "#3."); nav.MoveToRoot (); nav.MoveToFirstChild (); DocElem_OpenClose_Attribute (nav, "#4."); }
[Category ("NotDotNet")] // MS bug public void AttributesAndNamespaces () { string xml = "<root attr='value' x:a2='v2' xmlns:x='urn:foo' xmlns='urn:default'></root>"; nav = GetXmlDocumentNavigator (xml); AttributesAndNamespaces (nav, "#1."); nav.MoveToRoot (); nav.MoveToFirstChild (); AttributesAndNamespaces (nav, "#2."); nav = GetXPathDocumentNavigator (document); AttributesAndNamespaces (nav, "#3."); nav.MoveToRoot (); nav.MoveToFirstChild (); AttributesAndNamespaces (nav, "#4."); }
internal override XPathNavigator advance() { XPathNavigator res1, res2; XmlNodeOrder order = 0; if (advance1) { res1 = qy1.advance(); } else { res1 = _last; } if (advance2) { res2 = qy2.advance(); } else { res2 = _last; } if (res1 != null && res2 != null) { order = res1.ComparePosition(res2); } else if (res2 == null) { advance1 = true; advance2 = false; m_eNext = res1; _last = null; return(res1); } else { advance1 = false; advance2 = true; m_eNext = res2; _last = null; return(res2); } if (order == XmlNodeOrder.Same) { return(ProcessSamePosition(res1)); } if (order == XmlNodeOrder.Before) { return(ProcessBeforePosition(res1, res2)); } if (order == XmlNodeOrder.After) { return(ProcessAfterPosition(res1, res2)); } //Now order is XmlNodeOrder.Unknown XPathNavigator dummyres1 = res1.Clone(); dummyres1.MoveToRoot(); XPathNavigator dummyres2 = res2.Clone(); dummyres2.MoveToRoot(); int uriOrder = context.CompareDocument(dummyres1.BaseURI, dummyres2.BaseURI); if (uriOrder == 0) { return(ProcessSamePosition(res1)); } if (uriOrder < 0) { return(ProcessBeforePosition(res1, res2)); } if (uriOrder > 0) { return(ProcessAfterPosition(res1, res2)); } Debug.Assert(false, "should not be herein OrQuery.advance()"); return(null); }
internal static bool ExtractFromNavigator(XPathNavigator nav) { string actor = XPathMessageFunctionActor.ExtractFromNavigator(nav); nav.MoveToRoot(); if (!nav.MoveToFirstChild()) { return false; } if (nav.LocalName == XPathMessageContext.EnvelopeE) { if (nav.NamespaceURI == XPathMessageContext.S11NS) { return actor == S11UltRec; } else if (nav.NamespaceURI == XPathMessageContext.S12NS) { return actor == S12UltRec; } } return false; }
internal static bool MoveToBody(XPathNavigator nav) { nav.MoveToRoot(); if (!nav.MoveToFirstChild()) { return false; } string ns = nav.NamespaceURI; if (nav.LocalName != XPathMessageContext.EnvelopeE || (ns != XPathMessageContext.S11NS && ns != XPathMessageContext.S12NS)) { return false; } if (!nav.MoveToFirstChild()) { return false; } do { if (nav.LocalName == XPathMessageContext.BodyE && nav.NamespaceURI == ns) { return true; } } while (nav.MoveToNext()); return false; }
internal override XPathNavigator advance() { if (proceed) { if (temp == null ) { XPathNavigator _eLast = m_qyInput.advance(); while (_eLast != null){ temp = _eLast.Clone(); _eLast = m_qyInput.advance(); } if (temp == null || temp.NodeType == XPathNodeType.Root) return null; if (temp.NodeType == XPathNodeType.Attribute || temp.NodeType == XPathNodeType.Namespace){ temp.MoveToParent(); } NotVisited(temp.Clone()); _AncestorStk.Add(temp.Clone()); temp.MoveToRoot(); _qy = temp.SelectDescendants(XPathNodeType.All, false); } int flag; while ( _qy.MoveNext()) { m_eNext = _qy.Current; if (matches(m_eNext)){ flag = InStk(m_eNext); if (flag == 1){ _position++; return m_eNext; } if (flag == 2) { proceed = false; m_eNext = null; return null; } } else{ if (m_eNext.IsSamePosition((XPathNavigator)_AncestorStk[_AncestorStk.Count -1])) { proceed = false; m_eNext = null; return null; } } } return null; } return null; }
private void XmlSimpleTextContent (XPathNavigator nav) { AssertNavigator ("#1", nav, XPathNodeType.Root, "", "", "", "", "Test.", false, true, false); Assert.IsTrue (nav.MoveToFirstChild (), "#x1"); AssertNavigator ("#2", nav, XPathNodeType.Element, "", "foo", "", "foo", "Test.", false, true, false); Assert.IsTrue (!nav.MoveToNext (), "#x2"); Assert.IsTrue (!nav.MoveToPrevious (), "#x3"); Assert.IsTrue (nav.MoveToFirstChild (), "#x4"); AssertNavigator ("#3", nav, XPathNodeType.Text, "", "", "", "", "Test.", false, false, false); Assert.IsTrue (nav.MoveToParent (), "#x5"); AssertNavigator ("#4", nav, XPathNodeType.Element, "", "foo", "", "foo", "Test.", false, true, false); Assert.IsTrue (nav.MoveToParent (), "#x6"); AssertNavigator ("#5", nav, XPathNodeType.Root, "", "", "", "", "Test.", false, true, false); nav.MoveToFirstChild (); nav.MoveToFirstChild (); nav.MoveToRoot (); AssertNavigator ("#6", nav, XPathNodeType.Root, "", "", "", "", "Test.", false, true, false); Assert.IsTrue (!nav.MoveToNext (), "#x7"); }
internal static string ExtractFromNavigator(XPathNavigator nav) { string actor11 = nav.GetAttribute(XPathMessageContext.Actor11A, XPathMessageContext.S11NS); string actor12 = nav.GetAttribute(XPathMessageContext.Actor12A, XPathMessageContext.S12NS); nav.MoveToRoot(); nav.MoveToFirstChild(); if (nav.LocalName == XPathMessageContext.EnvelopeE && nav.NamespaceURI == XPathMessageContext.S11NS) { return actor11; } else if (nav.LocalName == XPathMessageContext.EnvelopeE && nav.NamespaceURI == XPathMessageContext.S12NS) { return actor12; } return string.Empty; }
/// <summary> /// Initialize the PrecedingIterator (no possibility of duplicates). /// </summary> public void Create(XPathNavigator context, XmlNavigatorFilter filter) { // Start at root, which is always first node in the document _navCurrent = XmlQueryRuntime.SyncToNavigator(_navCurrent, context); _navCurrent.MoveToRoot(); _stack.Reset(); // If root node is not the ending node, if (!_navCurrent.IsSamePosition(context)) { // Push root onto the stack if it is not filtered if (!filter.IsFiltered(_navCurrent)) _stack.Push(_navCurrent.Clone()); // Push all matching nodes onto stack while (filter.MoveToFollowing(_navCurrent, context)) _stack.Push(_navCurrent.Clone()); } }
public void Navigation () { document.LoadXml ("<foo><bar /><baz /></foo>"); navigator = document.DocumentElement.CreateNavigator (); Assert.AreEqual ("foo", navigator.Name, "#1"); Assert.IsTrue (navigator.MoveToFirstChild (), "#2"); Assert.AreEqual ("bar", navigator.Name, "#3"); Assert.IsTrue (navigator.MoveToNext (), "#4"); Assert.AreEqual ("baz", navigator.Name, "#5"); Assert.IsTrue (!navigator.MoveToNext (), "#6"); Assert.AreEqual ("baz", navigator.Name, "#7"); Assert.IsTrue (navigator.MoveToPrevious (), "#8"); Assert.AreEqual ("bar", navigator.Name, "#9"); Assert.IsTrue (!navigator.MoveToPrevious (), "#10"); Assert.IsTrue (navigator.MoveToParent (), "#11"); Assert.AreEqual ("foo", navigator.Name, "#12"); navigator.MoveToRoot (); Assert.AreEqual (XPathNodeType.Root, navigator.NodeType, "#13"); Assert.IsTrue (!navigator.MoveToParent (), "#14"); Assert.AreEqual (XPathNodeType.Root, navigator.NodeType, "#15"); Assert.IsTrue (navigator.MoveToFirstChild (), "#16"); Assert.AreEqual ("foo", navigator.Name, "#17"); Assert.IsTrue (navigator.MoveToFirst (), "#18"); Assert.AreEqual ("foo", navigator.Name, "#19"); Assert.IsTrue (navigator.MoveToFirstChild (), "#20"); Assert.AreEqual ("bar", navigator.Name, "#21"); Assert.IsTrue (navigator.MoveToNext (), "#22"); Assert.AreEqual ("baz", navigator.Name, "#23"); Assert.IsTrue (navigator.MoveToFirst (), "#24"); Assert.AreEqual ("bar", navigator.Name, "#25"); }
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); }
public void DocumentWithXmlDeclaration () { document.LoadXml ("<?xml version=\"1.0\" standalone=\"yes\"?><Root><foo>bar</foo></Root>"); navigator = document.CreateNavigator (); navigator.MoveToRoot (); navigator.MoveToFirstChild (); Assert.AreEqual (XPathNodeType.Element, navigator.NodeType, "#1"); Assert.AreEqual ("Root", navigator.Name, "#2"); }
public void MoveToFirstAttributeFromAttribute () { string xml = @"<one xmlns:foo='urn:foo' a='v' />"; nav = GetXmlDocumentNavigator (xml); MoveToFirstAttributeFromAttribute (nav, "#1."); nav.MoveToRoot (); nav.MoveToFirstChild (); MoveToFirstAttributeFromAttribute (nav, "#2."); nav = GetXPathDocumentNavigator (document); MoveToFirstAttributeFromAttribute (nav, "#3."); nav.MoveToRoot (); nav.MoveToFirstChild (); MoveToFirstAttributeFromAttribute (nav, "#4."); }
private void XmlRootElementOnly (XPathNavigator nav) { AssertNavigator ("#1", nav, XPathNodeType.Root, "", "", "", "", "", false, true, false); Assert.IsTrue (nav.MoveToFirstChild ()); AssertNavigator ("#2", nav, XPathNodeType.Element, "", "foo", "", "foo", "", false, false, true); Assert.IsTrue (!nav.MoveToFirstChild ()); Assert.IsTrue (!nav.MoveToNext ()); Assert.IsTrue (!nav.MoveToPrevious ()); nav.MoveToRoot (); AssertNavigator ("#3", nav, XPathNodeType.Root, "", "", "", "", "", false, true, false); Assert.IsTrue (!nav.MoveToNext ()); }
IEnumerable<FootballEvent> NavigateSprts(XPathNavigator nav) { // move to the root and the first element - <books> nav.MoveToRoot(); var sports = nav.Select("//rsp/fd/sports/sport"); while (sports.MoveNext()) { var sport = sports.Current; var sportName = _sportKindResonlver(GetIdFromNode(sport)); var leagues = sport.Select("leagues/league"); while (leagues.MoveNext()) { var leagueName = _leagueNameResolver(GetIdFromNode(leagues.Current)); var events = leagues.Current.Select("events/event"); while (events.MoveNext()) { var @event = events.Current; var eventid = GetIdFromNode(@event); var when = DateTimeOffset.Parse(GetChildNodeValue(@event, "startDateTime").First()); var homeTeam = GetChildNodeValue(@event, "homeTeam/name").First(); var awayTeam = GetChildNodeValue(@event, "awayTeam/name").First(); var periods = @event.Select("periods/period"); var pperiods = ParsePeriods(periods).ToArray(); yield return new FootballEvent { AwayTeam = awayTeam, HomeTeam = homeTeam, League = leagueName, Sport = sportName, Periods = pperiods, When = when }; } } } }
private void XmlElementWithAttributes (XPathNavigator nav) { nav.MoveToFirstChild (); AssertNavigator ("#1", nav, XPathNodeType.Element, "", "img", "", "img", "", true, false, true); Assert.IsTrue (!nav.MoveToNext ()); Assert.IsTrue (!nav.MoveToPrevious ()); Assert.IsTrue (nav.MoveToFirstAttribute ()); AssertNavigator ("#2", nav, XPathNodeType.Attribute, "", "src", "", "src", "foo.png", false, false, false); Assert.IsTrue (!nav.MoveToFirstAttribute ()); // On attributes, it fails. Assert.IsTrue (nav.MoveToNextAttribute ()); AssertNavigator ("#3", nav, XPathNodeType.Attribute, "", "alt", "", "alt", "image Fooooooo!", false, false, false); Assert.IsTrue (!nav.MoveToNextAttribute ()); Assert.IsTrue (nav.MoveToParent ()); AssertNavigator ("#4", nav, XPathNodeType.Element, "", "img", "", "img", "", true, false, true); Assert.IsTrue (nav.MoveToAttribute ("alt", "")); AssertNavigator ("#5", nav, XPathNodeType.Attribute, "", "alt", "", "alt", "image Fooooooo!", false, false, false); Assert.IsTrue (!nav.MoveToAttribute ("src", "")); // On attributes, it fails. Assert.IsTrue (nav.MoveToParent ()); Assert.IsTrue (nav.MoveToAttribute ("src", "")); AssertNavigator ("#6", nav, XPathNodeType.Attribute, "", "src", "", "src", "foo.png", false, false, false); nav.MoveToRoot (); AssertNavigator ("#7", nav, XPathNodeType.Root, "", "", "", "", "", false, true, false); }
private void XmlSimpleElementContent (XPathNavigator nav) { AssertNavigator (nav, XPathNodeType.Root, "", "", "", "", "", false, true, false); Assert (nav.MoveToFirstChild ()); AssertNavigator (nav, XPathNodeType.Element, "", "foo", "", "foo", "", false, true, false); Assert (!nav.MoveToNext ()); Assert (!nav.MoveToPrevious ()); Assert (nav.MoveToFirstChild ()); AssertNavigator (nav, XPathNodeType.Element, "", "bar", "", "bar", "", false, false, true); Assert (nav.MoveToParent ()); AssertNavigator (nav, XPathNodeType.Element, "", "foo", "", "foo", "", false, true, false); nav.MoveToRoot (); AssertNavigator (nav, XPathNodeType.Root, "", "", "", "", "", false, true, false); Assert (!nav.MoveToNext ()); }
public string CreateNamespace(string prefix, string namespaceUri, XPathNavigator source) { if (string.IsNullOrEmpty(namespaceUri) == false) { source = source.Clone(); source.MoveToRoot(); source.MoveToChild(XPathNodeType.Element); if (string.IsNullOrEmpty(prefix)) prefix = AddNamespace(namespaceUri); var existing = source.GetNamespace(prefix); if (existing == namespaceUri) return prefix; if (string.IsNullOrEmpty(existing) == false) return null; source.CreateAttribute("xmlns", prefix, "", namespaceUri); } return prefix; }
internal static string ExtractFromNavigator(XPathNavigator nav) { nav.MoveToRoot(); if (nav.MoveToFirstChild()) { string ns = nav.NamespaceURI; if (nav.LocalName != XPathMessageContext.EnvelopeE || (ns != XPathMessageContext.S11NS && ns != XPathMessageContext.S12NS)) { return string.Empty; } else { return ns; } } else { return string.Empty; } }
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 void MixedContentAndDepth () { string xml = @"<one> <two>Some data.<three>more</three> done.</two> </one>"; nav = GetXmlDocumentNavigator (xml); MixedContentAndDepth (nav, "#1."); nav.MoveToRoot (); nav.MoveToFirstChild (); MixedContentAndDepth (nav, "#2."); nav = GetXPathDocumentNavigator (document); MixedContentAndDepth (nav, "#3."); nav.MoveToRoot (); nav.MoveToFirstChild (); MixedContentAndDepth (nav, "#4."); }