public override bool MoveToFirstAttribute() { int num; XPathNavigator elemNav = this.GetElemNav(out num); if (elemNav != null) { if (elemNav.MoveToFirstNamespace(XPathNamespaceScope.Local)) { while (elemNav.MoveToNextNamespace(XPathNamespaceScope.Local)) { } goto Label_002A; } if (elemNav.MoveToFirstAttribute()) { goto Label_002A; } } return(false); Label_002A: if (this.state == State.InReadBinary) { this.readBinaryHelper.Finish(); this.state = this.savedState; } this.MoveToAttr(elemNav, num + 1); return(true); }
public virtual IDictionary <string, string> GetNamespacesInScope(XmlNamespaceScope scope) { IDictionary <string, string> table = new Dictionary <string, string> (); XPathNamespaceScope xpscope = scope == XmlNamespaceScope.Local ? XPathNamespaceScope.Local : scope == XmlNamespaceScope.ExcludeXml ? XPathNamespaceScope.ExcludeXml : XPathNamespaceScope.All; XPathNavigator nav = Clone(); if (nav.NodeType != XPathNodeType.Element) { nav.MoveToParent(); } if (!nav.MoveToFirstNamespace(xpscope)) { return(table); } do { table.Add(nav.Name, nav.Value); } while (nav.MoveToNextNamespace(xpscope)); return(table); }
public override bool MoveToFirstAttribute() { int depth; XPathNavigator nav = GetElemNav(out depth); if (null != nav) { if (nav.MoveToFirstNamespace(XPathNamespaceScope.Local)) { // attributes are in reverse order while (nav.MoveToNextNamespace(XPathNamespaceScope.Local)) { ; } goto FoundMatch; } if (nav.MoveToFirstAttribute()) { goto FoundMatch; } } return(false); FoundMatch: if (_state == State.InReadBinary) { _readBinaryHelper.Finish(); _state = _savedState; } MoveToAttr(nav, depth + 1); return(true); }
private XmlNodeOrder CompareSiblings(XPathNavigator n1, XPathNavigator n2) { bool attr1 = n1.NodeType == XPathNodeType.Attribute; bool attr2 = n2.NodeType == XPathNodeType.Attribute; bool ns1 = n1.NodeType == XPathNodeType.Namespace; bool ns2 = n2.NodeType == XPathNodeType.Namespace; if (!ns1 && !ns2 && !attr1 && !attr2) { while (n1.MoveToNext()) { if (n1.IsSamePosition(n2)) { return(XmlNodeOrder.Before); } } return(XmlNodeOrder.After); } if (attr1 && attr2) { while (n1.MoveToNextAttribute()) { if (n1.IsSamePosition(n2)) { return(XmlNodeOrder.Before); } } return(XmlNodeOrder.After); } if (attr1) { return(XmlNodeOrder.After); } if (attr2) { return(XmlNodeOrder.Before); } if (ns1 && ns2) { while (n1.MoveToNextNamespace()) { if (n1.IsSamePosition(n2)) { return(XmlNodeOrder.Before); } } return(XmlNodeOrder.After); } if (ns1) { return(XmlNodeOrder.After); } Debug.Assert(ns2); return(XmlNodeOrder.Before); }
public override bool MoveToAttribute(string localName, string namespaceName) { if (localName == null) { throw new ArgumentNullException("localName"); } int depth = this.depth; XPathNavigator elemNav = this.GetElemNav(out depth); if (elemNav != null) { if (namespaceName == "http://www.w3.org/2000/xmlns/") { if (localName == "xmlns") { localName = string.Empty; } if (elemNav.MoveToFirstNamespace(XPathNamespaceScope.Local)) { do { if (elemNav.LocalName == localName) { goto Label_007A; } }while (elemNav.MoveToNextNamespace(XPathNamespaceScope.Local)); } } else { if (namespaceName == null) { namespaceName = string.Empty; } if (elemNav.MoveToAttribute(localName, namespaceName)) { goto Label_007A; } } } return(false); Label_007A: if (this.state == State.InReadBinary) { this.readBinaryHelper.Finish(); this.state = this.savedState; } this.MoveToAttr(elemNav, depth + 1); return(true); }
public override bool MoveToAttribute(string localName, string namespaceName) { if (null == localName) { throw new ArgumentNullException("localName"); } int depth = _depth; XPathNavigator nav = GetElemNav(out depth); if (null != nav) { if (namespaceName == XmlConst.ReservedNsXmlNs) { if (localName == "xmlns") { localName = string.Empty; } if (nav.MoveToFirstNamespace(XPathNamespaceScope.Local)) { do { if (nav.LocalName == localName) { goto FoundMatch; } } while (nav.MoveToNextNamespace(XPathNamespaceScope.Local)); } } else { if (null == namespaceName) { namespaceName = string.Empty; } if (nav.MoveToAttribute(localName, namespaceName)) { goto FoundMatch; } } } return(false); FoundMatch: if (_state == State.InReadBinary) { _readBinaryHelper.Finish(); _state = _savedState; } MoveToAttr(nav, depth + 1); return(true); }
private static void WriteLocalNamespaces(this XmlWriter writer, XPathNavigator nsNav) { string prefix = nsNav.LocalName; string ns = nsNav.Value; if (nsNav.MoveToNextNamespace(XPathNamespaceScope.Local)) { writer.WriteLocalNamespaces(nsNav); } if (prefix.Length == 0) { writer.WriteAttributeString(string.Empty, "xmlns", XmlConst.ReservedNsXmlNs, ns); } else { writer.WriteAttributeString("xmlns", prefix, XmlConst.ReservedNsXmlNs, ns); } }
private static void WriteLocalNamespaces(this XmlWriter writer, XPathNavigator nsNav) { string prefix = nsNav.LocalName; string ns = nsNav.Value; if (nsNav.MoveToNextNamespace(XPathNamespaceScope.Local)) { writer.WriteLocalNamespaces(nsNav); } if (prefix.Length == 0) { writer.WriteAttributeString(string.Empty, "xmlns", XmlConst.ReservedNsXmlNs, ns); } else { writer.WriteAttributeString("xmlns", prefix, XmlConst.ReservedNsXmlNs, ns); } }
private static string GetNamespaceByIndex(XPathNavigator nav, int index, out int count) { string str = nav.Value; string str2 = null; if (nav.MoveToNextNamespace(XPathNamespaceScope.Local)) { str2 = GetNamespaceByIndex(nav, index, out count); } else { count = 0; } if (count == index) { str2 = str; } count++; return(str2); }
virtual string LookupPrefix(string namespaceUri) { XPathNavigator nav = Clone(); if (nav.NodeType != XPathNodeType.Element) { nav.MoveToParent(); } if (!nav.MoveToFirstNamespace()) { return(null); } do { if (nav.Value == namespaceUri) { return(nav.Name); } } while (nav.MoveToNextNamespace()); return(null); }
private static string GetNamespaceByIndex(XPathNavigator nav, int index, out int count) { string thisValue = nav.Value; string value = null; if (nav.MoveToNextNamespace(XPathNamespaceScope.Local)) { value = GetNamespaceByIndex(nav, index, out count); } else { count = 0; } if (count == index) { Debug.Assert(value == null); value = thisValue; } count++; return(value); }
private void MoveToNamespaces (XPathNavigator nav) { XPathNodeIterator iter = nav.Select ("//e"); iter.MoveNext (); nav.MoveTo (iter.Current); Assert.AreEqual ("e", nav.Name, "#1"); nav.MoveToFirstNamespace (); Assert.AreEqual ("x", nav.Name, "#2"); nav.MoveToNextNamespace (); Assert.AreEqual ("xml", nav.Name, "#3"); }
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 XmlNodeOrder CompareSiblings(XPathNavigator n1, XPathNavigator n2) { int num = 0; switch (n1.NodeType) { case XPathNodeType.Attribute: num++; break; case XPathNodeType.Namespace: break; default: num += 2; break; } switch (n2.NodeType) { case XPathNodeType.Attribute: num--; if (num == 0) { while (n1.MoveToNextAttribute()) { if (n1.IsSamePosition(n2)) { return XmlNodeOrder.Before; } } } break; case XPathNodeType.Namespace: if (num == 0) { while (n1.MoveToNextNamespace()) { if (n1.IsSamePosition(n2)) { return XmlNodeOrder.Before; } } } break; default: num -= 2; if (num == 0) { while (n1.MoveToNext()) { if (n1.IsSamePosition(n2)) { return XmlNodeOrder.Before; } } } break; } if (num >= 0) { return XmlNodeOrder.After; } return XmlNodeOrder.Before; }
// Copy local namespaces on the navigator's current node to the raw writer. The namespaces are returned by the navigator in reversed order. // The recursive call reverses them back. private void WriteLocalNamespaces(XPathNavigator nsNav) { string prefix = nsNav.LocalName; string ns = nsNav.Value; if (nsNav.MoveToNextNamespace(XPathNamespaceScope.Local)) { WriteLocalNamespaces(nsNav); } if (prefix.Length == 0) { WriteAttributeString(string.Empty, "xmlns", XmlReservedNs.NsXmlNs, ns); } else { WriteAttributeString("xmlns", prefix, XmlReservedNs.NsXmlNs, ns); } }
private void WriteLocalNamespaces(XPathNavigator nsNav) { string localName = nsNav.LocalName; string str2 = nsNav.Value; if (nsNav.MoveToNextNamespace(XPathNamespaceScope.Local)) { this.WriteLocalNamespaces(nsNav); } if (localName.Length == 0) { this.WriteAttributeString(string.Empty, "xmlns", "http://www.w3.org/2000/xmlns/", str2); } else { this.WriteAttributeString("xmlns", localName, "http://www.w3.org/2000/xmlns/", str2); } }
private static string GetNamespaceByIndex(XPathNavigator nav, int index, out int count) { string thisValue = nav.Value; string value = null; if (nav.MoveToNextNamespace(XPathNamespaceScope.Local)) { value = GetNamespaceByIndex(nav, index, out count); } else { count = 0; } if (count == index) { Debug.Assert(value == null); value = thisValue; } count++; return value; }
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); } }
public virtual void WriteNode (XPathNavigator navigator, bool defattr) { if (navigator == null) throw new ArgumentNullException ("navigator"); switch (navigator.NodeType) { case XPathNodeType.Attribute: // no operation break; case XPathNodeType.Namespace: // no operation break; case XPathNodeType.Text: WriteString (navigator.Value); break; case XPathNodeType.SignificantWhitespace: WriteWhitespace (navigator.Value); break; case XPathNodeType.Whitespace: WriteWhitespace (navigator.Value); break; case XPathNodeType.Comment: WriteComment (navigator.Value); break; case XPathNodeType.ProcessingInstruction: WriteProcessingInstruction (navigator.Name, navigator.Value); break; case XPathNodeType.Root: if (navigator.MoveToFirstChild ()) { do { WriteNode (navigator, defattr); } while (navigator.MoveToNext ()); navigator.MoveToParent (); } break; case XPathNodeType.Element: WriteStartElement (navigator.Prefix, navigator.LocalName, navigator.NamespaceURI); if (navigator.MoveToFirstNamespace (XPathNamespaceScope.Local)) { do { if (defattr || navigator.SchemaInfo == null || navigator.SchemaInfo.IsDefault) WriteAttributeString (navigator.Prefix, navigator.LocalName == String.Empty ? "xmlns" : navigator.LocalName, "http://www.w3.org/2000/xmlns/", navigator.Value); } while (navigator.MoveToNextNamespace (XPathNamespaceScope.Local)); navigator.MoveToParent (); } if (navigator.MoveToFirstAttribute ()) { do { if (defattr || navigator.SchemaInfo == null || navigator.SchemaInfo.IsDefault) WriteAttributeString (navigator.Prefix, navigator.LocalName, navigator.NamespaceURI, navigator.Value); } while (navigator.MoveToNextAttribute ()); navigator.MoveToParent (); } if (navigator.MoveToFirstChild ()) { do { WriteNode (navigator, defattr); } while (navigator.MoveToNext ()); navigator.MoveToParent (); } if (navigator.IsEmptyElement) WriteEndElement (); else WriteFullEndElement (); break; default: throw new NotSupportedException (); } }
public CompiledStylesheet Compile (XPathNavigator nav, XmlResolver res, Evidence evidence) { this.xpathParser = new XPathParser (this); this.patternParser = new XsltPatternParser (this); this.res = res; if (res == null) this.res = new XmlUrlResolver (); this.evidence = evidence; // reject empty document. if (nav.NodeType == XPathNodeType.Root && !nav.MoveToFirstChild ()) throw new XsltCompileException ("Stylesheet root element must be either \"stylesheet\" or \"transform\" or any literal element", null, nav); while (nav.NodeType != XPathNodeType.Element) nav.MoveToNext(); stylesheetVersion = nav.GetAttribute ("version", (nav.NamespaceURI != XsltNamespace) ? XsltNamespace : String.Empty); outputs [""] = new XslOutput ("", stylesheetVersion); PushInputDocument (nav); if (nav.MoveToFirstNamespace (XPathNamespaceScope.ExcludeXml)) { do { nsMgr.AddNamespace (nav.LocalName, nav.Value); } while (nav.MoveToNextNamespace (XPathNamespaceScope.ExcludeXml)); nav.MoveToParent (); } try { rootStyle = new XslStylesheet (); rootStyle.Compile (this); } catch (XsltCompileException) { throw; } catch (Exception x) { throw new XsltCompileException ("XSLT compile error. " + x.Message, x, Input); } return new CompiledStylesheet (rootStyle, globalVariables, attrSets, nsMgr, keys, outputs, decimalFormats, msScripts); }
void CopyNode (XslTransformProcessor p, XPathNavigator nav) { Outputter outputter = p.Out; switch (nav.NodeType) { case XPathNodeType.Root: XPathNodeIterator itr = nav.SelectChildren (XPathNodeType.All); while (itr.MoveNext ()) CopyNode (p, itr.Current); break; case XPathNodeType.Element: bool isCData = p.InsideCDataElement; string prefix = nav.Prefix; string ns = nav.NamespaceURI; p.PushElementState (prefix, nav.LocalName, ns, false); outputter.WriteStartElement (prefix, nav.LocalName, ns); if (nav.MoveToFirstNamespace (XPathNamespaceScope.ExcludeXml)) { do { if (prefix == nav.Name) continue; if (nav.Name.Length == 0 && ns.Length == 0) continue; outputter.WriteNamespaceDecl (nav.Name, nav.Value); } while (nav.MoveToNextNamespace (XPathNamespaceScope.ExcludeXml)); nav.MoveToParent (); } if (nav.MoveToFirstAttribute()) { do { outputter.WriteAttributeString (nav.Prefix, nav.LocalName, nav.NamespaceURI, nav.Value); } while (nav.MoveToNextAttribute ()); nav.MoveToParent(); } if (nav.MoveToFirstChild ()) { do { CopyNode (p, nav); } while (nav.MoveToNext ()); nav.MoveToParent (); } if (nav.IsEmptyElement) outputter.WriteEndElement (); else outputter.WriteFullEndElement (); p.PopCDataState (isCData); break; case XPathNodeType.Namespace: if (nav.Name != p.XPathContext.ElementPrefix && (p.XPathContext.ElementNamespace.Length > 0 || nav.Name.Length > 0)) outputter.WriteNamespaceDecl (nav.Name, nav.Value); break; case XPathNodeType.Attribute: outputter.WriteAttributeString (nav.Prefix, nav.LocalName, nav.NamespaceURI, nav.Value); break; case XPathNodeType.Whitespace: case XPathNodeType.SignificantWhitespace: bool cdata = outputter.InsideCDataSection; outputter.InsideCDataSection = false; outputter.WriteString (nav.Value); outputter.InsideCDataSection = cdata; break; case XPathNodeType.Text: outputter.WriteString (nav.Value); break; case XPathNodeType.ProcessingInstruction: outputter.WriteProcessingInstruction (nav.Name, nav.Value); break; case XPathNodeType.Comment: outputter.WriteComment (nav.Value); break; } }
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 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 bool MoveToAttribute(string name) { int num; string str; string str2; XPathNavigator elemNav = this.GetElemNav(out num); if (elemNav == null) { return(false); } ValidateNames.SplitQName(name, out str, out str2); bool flag = false; if ((flag = (str.Length == 0) && (str2 == "xmlns")) || (str == "xmlns")) { if (flag) { str2 = string.Empty; } if (elemNav.MoveToFirstNamespace(XPathNamespaceScope.Local)) { do { if (elemNav.LocalName == str2) { goto Label_00B5; } }while (elemNav.MoveToNextNamespace(XPathNamespaceScope.Local)); } } else { if (str.Length == 0) { if (!elemNav.MoveToAttribute(str2, string.Empty)) { goto Label_00B3; } goto Label_00B5; } if (elemNav.MoveToFirstAttribute()) { do { if ((elemNav.LocalName == str2) && (elemNav.Prefix == str)) { goto Label_00B5; } }while (elemNav.MoveToNextAttribute()); } } Label_00B3: return(false); Label_00B5: if (this.state == State.InReadBinary) { this.readBinaryHelper.Finish(); this.state = this.savedState; } this.MoveToAttr(elemNav, num + 1); return(true); }
private static string GetNamespaceByIndex(XPathNavigator nav, int index, out int count) { string str = nav.Value; string str2 = null; if (nav.MoveToNextNamespace(XPathNamespaceScope.Local)) { str2 = GetNamespaceByIndex(nav, index, out count); } else { count = 0; } if (count == index) { str2 = str; } count++; return str2; }
/// <summary> /// Copy all or some (which depends on nsScope) of the namespaces on the navigator's current node to the /// raw writer. /// </summary> private void CopyNamespaces(XPathNavigator nav, XPathNamespaceScope nsScope) { string prefix = nav.LocalName; string ns = nav.Value; if (nav.MoveToNextNamespace(nsScope)) { CopyNamespaces(nav, nsScope); } this.xwrt.WriteNamespaceDeclaration(prefix, ns); }
// Copy local namespaces on the navigator's current node to the raw writer. The namespaces are returned by the navigator in reversed order. // The recursive call reverses them back. private async Task WriteLocalNamespacesAsync(XPathNavigator nsNav) { string prefix = nsNav.LocalName; string ns = nsNav.Value; if (nsNav.MoveToNextNamespace(XPathNamespaceScope.Local)) { await WriteLocalNamespacesAsync(nsNav).ConfigureAwait(false); } if (prefix.Length == 0) { await WriteAttributeStringAsync(string.Empty, "xmlns", XmlReservedNs.NsXmlNs, ns).ConfigureAwait(false); } else { await WriteAttributeStringAsync("xmlns", prefix, XmlReservedNs.NsXmlNs, ns).ConfigureAwait(false); } }
/// <summary> /// Initialize the NamespaceIterator. /// </summary> public void Create(XPathNavigator context) { // Push all of context's in-scope namespaces onto a stack in order to return them in document order // (MoveToXXXNamespace methods return namespaces in reverse document order) this.navStack.Reset(); if (context.MoveToFirstNamespace(XPathNamespaceScope.All)) { do { // Don't return the default namespace undeclaration if (context.LocalName.Length != 0 || context.Value.Length != 0) this.navStack.Push(context.Clone()); } while (context.MoveToNextNamespace(XPathNamespaceScope.All)); context.MoveToParent(); } }
private XmlNodeOrder CompareSiblings(XPathNavigator n1, XPathNavigator n2){ bool attr1 = n1.NodeType == XPathNodeType.Attribute; bool attr2 = n2.NodeType == XPathNodeType.Attribute; bool ns1 = n1.NodeType == XPathNodeType.Namespace; bool ns2 = n2.NodeType == XPathNodeType.Namespace; if (! ns1 && ! ns2 && ! attr1 && ! attr2) { while (n1.MoveToNext()) { if (n1.IsSamePosition(n2)) return XmlNodeOrder.Before; } return XmlNodeOrder.After; } if (attr1 && attr2) { while (n1.MoveToNextAttribute()){ if (n1.IsSamePosition(n2)) return XmlNodeOrder.Before; } return XmlNodeOrder.After; } if (attr1){ return XmlNodeOrder.After; } if (attr2){ return XmlNodeOrder.Before; } if (ns1 && ns2) { while (n1.MoveToNextNamespace()) { if (n1.IsSamePosition(n2)) return XmlNodeOrder.Before; } return XmlNodeOrder.After; } if (ns1){ return XmlNodeOrder.After; } Debug.Assert(ns2); return XmlNodeOrder.Before; }
public override bool MoveToAttribute(string name) { int depth; XPathNavigator nav = GetElemNav(out depth); if (null == nav) { return(false); } string prefix, localname; ValidateNames.SplitQName(name, out prefix, out localname); // watch for a namespace name bool IsXmlnsNoPrefix = false; if ((IsXmlnsNoPrefix = (0 == prefix.Length && localname == "xmlns")) || (prefix == "xmlns")) { if (IsXmlnsNoPrefix) { localname = string.Empty; } if (nav.MoveToFirstNamespace(XPathNamespaceScope.Local)) { do { if (nav.LocalName == localname) { goto FoundMatch; } } while (nav.MoveToNextNamespace(XPathNamespaceScope.Local)); } } else if (0 == prefix.Length) { // the empty prefix always means empty namespaceUri for attributes if (nav.MoveToAttribute(localname, string.Empty)) { goto FoundMatch; } } else { if (nav.MoveToFirstAttribute()) { do { if (nav.LocalName == localname && nav.Prefix == prefix) { goto FoundMatch; } } while (nav.MoveToNextAttribute()); } } return(false); FoundMatch: if (_state == State.InReadBinary) { _readBinaryHelper.Finish(); _state = _savedState; } MoveToAttr(nav, depth + 1); return(true); }
// XPath based comparison for namespaces, attributes and other // items with the same parent element. // // n2 // namespace(0) attribute(-1) other(-2) // n1 // namespace(0) ?(0) before(-1) before(-2) // attribute(1) after(1) ?(0) before(-1) // other (2) after(2) after(1) ?(0) private static XmlNodeOrder CompareSiblings(XPathNavigator n1, XPathNavigator n2) { int cmp = 0; #if DEBUG Debug.Assert(!n1.IsSamePosition(n2)); XPathNavigator p1 = n1.Clone(), p2 = n2.Clone(); Debug.Assert(p1.MoveToParent() && p2.MoveToParent() && p1.IsSamePosition(p2)); #endif switch (n1.NodeType) { case XPathNodeType.Namespace: break; case XPathNodeType.Attribute: cmp += 1; break; default: cmp += 2; break; } switch (n2.NodeType) { case XPathNodeType.Namespace: if (cmp == 0) { while (n1.MoveToNextNamespace()) { if (n1.IsSamePosition(n2)) { return XmlNodeOrder.Before; } } } break; case XPathNodeType.Attribute: cmp -= 1; if (cmp == 0) { while (n1.MoveToNextAttribute()) { if (n1.IsSamePosition(n2)) { return XmlNodeOrder.Before; } } } break; default: cmp -= 2; if (cmp == 0) { while (n1.MoveToNext()) { if (n1.IsSamePosition(n2)) { return XmlNodeOrder.Before; } } } break; } return cmp < 0 ? XmlNodeOrder.Before : XmlNodeOrder.After; }
/// <summary> /// Recursive helper function that reverses order of the namespaces retrieved by MoveToFirstNamespace and /// MoveToNextNamespace. /// </summary> private void CopyNamespacesHelper(XPathNavigator navigator, XPathNamespaceScope nsScope) { string prefix = navigator.LocalName; string ns = navigator.Value; if (navigator.MoveToNextNamespace(nsScope)) CopyNamespacesHelper(navigator, nsScope); // No possibility for conflict, since we're copying namespaces from well-formed element WriteNamespaceDeclarationUnchecked(prefix, ns); }
private void ProcessElementNode(XPathNavigator node, InternalFormContext ctx) { Debug.Assert(node.NodeType == XPathNodeType.Element); log.Debug("Processing element node: {0} ({1})", node.Name, node.NamespaceURI); if (IsPreprocessElement(node)) { PreprocessElementNode(node, ctx); } else { ctx.Output.WriteStartElement(node.Prefix, node.LocalName, node.NamespaceURI); if (node.MoveToFirstAttribute()) { do { ctx.Output.WriteAttributeString(node.Prefix, node.LocalName, node.NamespaceURI, node.Value); } while (node.MoveToNextAttribute()); node.MoveToParent(); } if (!ctx.FirstElementHandled) { if (node.MoveToFirstNamespace()) { do { log.Debug("Writing namespace declaration: {0}:{1}", node.LocalName, node.Value); ctx.Output.WriteAttributeString("xmlns", node.LocalName, null, node.Value); } while (node.MoveToNextNamespace()); node.MoveToParent(); } ctx.FirstElementHandled = true; } if (!node.IsEmptyElement) { VisitChildren(node, ctx); } ctx.Output.WriteEndElement(); log.Debug("End processing element node: {0} ({1})", node.Name, node.NamespaceURI); } }