MoveToFirstNamespace() public method

public MoveToFirstNamespace ( ) : bool
return bool
Example #1
0
        /// <summary>
        /// Copy the navigator subtree to the raw writer.
        /// </summary>
        private void CopyNode(XPathNavigator nav) {
            XPathNodeType nodeType;
            int iLevel = 0;

            while (true) {
                if (CopyShallowNode(nav)) {
                    nodeType = nav.NodeType;
                    if (nodeType == XPathNodeType.Element) {
                        // Copy attributes
                        if (nav.MoveToFirstAttribute()) {
                            do {
                                CopyShallowNode(nav);
                            }
                            while (nav.MoveToNextAttribute());
                            nav.MoveToParent();
                        }

                        // Copy namespaces in document order (navigator returns them in reverse document order)
                        XPathNamespaceScope nsScope = (iLevel == 0) ? XPathNamespaceScope.ExcludeXml : XPathNamespaceScope.Local;
                        if (nav.MoveToFirstNamespace(nsScope)) {
                            CopyNamespaces(nav, nsScope);
                            nav.MoveToParent();
                        }

                        this.xwrt.StartElementContent();
                    }

                    // If children exist, move down to next level
                    if (nav.MoveToFirstChild()) {
                        iLevel++;
                        continue;
                    }
                    else {
                        // EndElement
                        if (nav.NodeType == XPathNodeType.Element)
                            this.xwrt.WriteEndElement(nav.Prefix, nav.LocalName, nav.NamespaceURI);
                    }
                }

                // No children
                while (true) {
                    if (iLevel == 0) {
                        // The entire subtree has been copied
                        return;
                    }

                    if (nav.MoveToNext()) {
                        // Found a sibling, so break to outer loop
                        break;
                    }

                    // No siblings, so move up to previous level
                    iLevel--;
                    nav.MoveToParent();

                    // EndElement
                    if (nav.NodeType == XPathNodeType.Element)
                        this.xwrt.WriteFullEndElement(nav.Prefix, nav.LocalName, nav.NamespaceURI);
                }
            }
        }
Example #2
0
        // Copies the current node from the given XPathNavigator to the writer (including child nodes).
        public virtual void WriteNode(XPathNavigator navigator, bool defattr)
        {
            if (navigator == null)
            {
                throw new ArgumentNullException(nameof(navigator));
            }
            int iLevel = 0;

            navigator = navigator.Clone();

            while (true)
            {
                bool mayHaveChildren = false;
                XPathNodeType nodeType = navigator.NodeType;

                switch (nodeType)
                {
                    case XPathNodeType.Element:
                        WriteStartElement(navigator.Prefix, navigator.LocalName, navigator.NamespaceURI);

                        // Copy attributes
                        if (navigator.MoveToFirstAttribute())
                        {
                            do
                            {
                                IXmlSchemaInfo schemaInfo = navigator.SchemaInfo;
                                if (defattr || (schemaInfo == null || !schemaInfo.IsDefault))
                                {
                                    WriteStartAttribute(navigator.Prefix, navigator.LocalName, navigator.NamespaceURI);
                                    // copy string value to writer
                                    WriteString(navigator.Value);
                                    WriteEndAttribute();
                                }
                            } while (navigator.MoveToNextAttribute());
                            navigator.MoveToParent();
                        }

                        // Copy namespaces
                        if (navigator.MoveToFirstNamespace(XPathNamespaceScope.Local))
                        {
                            WriteLocalNamespaces(navigator);
                            navigator.MoveToParent();
                        }
                        mayHaveChildren = true;
                        break;
                    case XPathNodeType.Attribute:
                        // do nothing on root level attribute
                        break;
                    case XPathNodeType.Text:
                        WriteString(navigator.Value);
                        break;
                    case XPathNodeType.SignificantWhitespace:
                    case XPathNodeType.Whitespace:
                        WriteWhitespace(navigator.Value);
                        break;
                    case XPathNodeType.Root:
                        mayHaveChildren = true;
                        break;
                    case XPathNodeType.Comment:
                        WriteComment(navigator.Value);
                        break;
                    case XPathNodeType.ProcessingInstruction:
                        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)
                            {
                                WriteEndElement();
                            }
                            else
                            {
                                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)
                        WriteFullEndElement();
                }
            }
        }
Example #3
0
        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);
        }
        /// <summary>
        /// Copy all namespaces of the specified type (in-scope, exclude-xml, local) in document order to output.
        /// </summary>
        private void CopyNamespaces(XPathNavigator navigator, XPathNamespaceScope nsScope) {
            Debug.Assert(navigator.NodeType == XPathNodeType.Element, "Only elements have namespaces to copy");

            // Default namespace undeclaration isn't included in navigator's namespace list, so add it now
            if (navigator.NamespaceURI.Length == 0) {
                Debug.Assert(navigator.LocalName.Length != 0, "xmlns:foo='' isn't allowed");
                WriteNamespaceDeclarationUnchecked(string.Empty, string.Empty);
            }

            // Since the namespace list is arranged in reverse-document order, recursively reverse it.
            if (navigator.MoveToFirstNamespace(nsScope)) {
                CopyNamespacesHelper(navigator, nsScope);
                navigator.MoveToParent();
            }
        }
Example #5
0
        /// <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();
            }
        }
Example #6
0
        public override bool MoveToNextAttribute()
        {
            switch (this.state)
            {
            case State.Content:
                return(MoveToFirstAttribute());

            case State.Attribute:
            {
                if (XPathNodeType.Attribute == this.nav.NodeType)
                {
                    return(this.nav.MoveToNextAttribute());
                }

                // otherwise it is on a namespace... namespace are in reverse order
                Debug.Assert(XPathNodeType.Namespace == this.nav.NodeType);
                XPathNavigator nav = this.nav.Clone();
                if (!nav.MoveToParent())
                {
                    return(false);        // shouldn't happen
                }
                if (!nav.MoveToFirstNamespace(XPathNamespaceScope.Local))
                {
                    return(false);        // shouldn't happen
                }
                if (nav.IsSamePosition(this.nav))
                {
                    // this was the last one... start walking attributes
                    nav.MoveToParent();
                    if (!nav.MoveToFirstAttribute())
                    {
                        return(false);
                    }
                    // otherwise we are there
                    this.nav.MoveTo(nav);
                    return(true);
                }
                else
                {
                    XPathNavigator prev = nav.Clone();
                    for (;;)
                    {
                        if (!nav.MoveToNextNamespace(XPathNamespaceScope.Local))
                        {
                            Debug.Assert(false, "Couldn't find Namespace Node! Should not happen!");
                            return(false);
                        }
                        if (nav.IsSamePosition(this.nav))
                        {
                            this.nav.MoveTo(prev);
                            return(true);
                        }
                        prev.MoveTo(nav);
                    }
                    // found previous namespace position
                }
            }

            case State.AttrVal:
                depth--;
                this.state = State.Attribute;
                if (!MoveToNextAttribute())
                {
                    depth++;
                    this.state = State.AttrVal;
                    return(false);
                }
                this.nodeType = XmlNodeType.Attribute;
                return(true);

            case State.InReadBinary:
                state = savedState;
                if (!MoveToNextAttribute())
                {
                    state = State.InReadBinary;
                    return(false);
                }
                readBinaryHelper.Finish();
                return(true);

            default:
                return(false);
            }
        }
Example #7
0
        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();
                    }
                }
            }
        }
        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);
        }
Example #9
0
		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);
		}
Example #10
0
		public void ReadSubtreeNamespace ()
		{
			string xml = "<root xmlns='urn:foo' />";
			nav = GetXmlDocumentNavigator (xml);
			nav.MoveToFirstChild ();
			nav.MoveToFirstNamespace ();
			nav.ReadSubtree ();
		}
Example #11
0
		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 virtual void WriteNode(XPathNavigator navigator, bool defattr)
        {
            bool flag;
            if (navigator == null)
            {
                throw new ArgumentNullException("navigator");
            }
            int num = 0;
            navigator = navigator.Clone();
        Label_0018:
            flag = false;
            switch (navigator.NodeType)
            {
                case XPathNodeType.Root:
                    flag = true;
                    break;

                case XPathNodeType.Element:
                    this.WriteStartElement(navigator.Prefix, navigator.LocalName, navigator.NamespaceURI);
                    if (navigator.MoveToFirstAttribute())
                    {
                        do
                        {
                            IXmlSchemaInfo schemaInfo = navigator.SchemaInfo;
                            if ((defattr || (schemaInfo == null)) || !schemaInfo.IsDefault)
                            {
                                this.WriteStartAttribute(navigator.Prefix, navigator.LocalName, navigator.NamespaceURI);
                                this.WriteString(navigator.Value);
                                this.WriteEndAttribute();
                            }
                        }
                        while (navigator.MoveToNextAttribute());
                        navigator.MoveToParent();
                    }
                    if (navigator.MoveToFirstNamespace(XPathNamespaceScope.Local))
                    {
                        this.WriteLocalNamespaces(navigator);
                        navigator.MoveToParent();
                    }
                    flag = true;
                    break;

                case XPathNodeType.Text:
                    this.WriteString(navigator.Value);
                    break;

                case XPathNodeType.SignificantWhitespace:
                case XPathNodeType.Whitespace:
                    this.WriteWhitespace(navigator.Value);
                    break;

                case XPathNodeType.ProcessingInstruction:
                    this.WriteProcessingInstruction(navigator.LocalName, navigator.Value);
                    break;

                case XPathNodeType.Comment:
                    this.WriteComment(navigator.Value);
                    break;
            }
            if (flag)
            {
                if (navigator.MoveToFirstChild())
                {
                    num++;
                    goto Label_0018;
                }
                if (navigator.NodeType == XPathNodeType.Element)
                {
                    if (navigator.IsEmptyElement)
                    {
                        this.WriteEndElement();
                    }
                    else
                    {
                        this.WriteFullEndElement();
                    }
                }
            }
            while (num != 0)
            {
                if (navigator.MoveToNext())
                {
                    goto Label_0018;
                }
                num--;
                navigator.MoveToParent();
                if (navigator.NodeType == XPathNodeType.Element)
                {
                    this.WriteFullEndElement();
                }
            }
        }
        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);
        }
		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);
		}
Example #15
0
		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 ();
			}
		}
		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");
		}
Example #17
0
        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);
            }
        }