Microsoft KB Archive/316808

= FIX: XPathNavigator.MoveToNextNamespace with XPathNamespaceScope.Local =

Article ID: 316808

Article Last Modified on 9/18/2003

-

APPLIES TO


 * Microsoft .NET Framework 1.0

-



This article was previously published under Q316808



SYMPTOMS
If an XML node has two namespaces defined as follows:  When you call the XPathNavigator.MoveToNextNamespace method with the input parameter of XPathNamespaceScope as XPathNamespaceScope.Local to navigate to the next namepace, an incorrect result is returned.

After you call the XPathNavigator.MoveToFirstNamespace(XPathNamespaceScope.Local) method, calling MoveToNextNamespace(XPathNamespaceScope.Local) returns false instead of moving to the next namespace.



RESOLUTION
This problem occurs only with the XmlDocument class; to work around the problem, use the XPathDocument class.



STATUS
This bug was corrected in Microsoft .NET Class Libraries 1.1.



Steps to Reproduce Behavior
 Create a new empty Microsoft Visual C# project, and be sure to add a reference to the System.XML namespace to the empty project.  Paste the following code in a new file and and save it as Q316808.cs. (The file name can be any valid name). using System; using System.Xml; using System.Xml.XPath; using System.Diagnostics;

namespace XmlTest {   class Class1 {       [STAThread] static void Main(string[] args) {           // Create document. string xml = &quot;&quot;; XmlDocument doc = new XmlDocument; doc.LoadXml(xml);

// Create XPath navigator. XPathNavigator nav = doc.CreateNavigator; Console.WriteLine(&quot;Checking navigator\r\n&quot;);

// Reproduce the problem. nav.MoveToRoot; Console.WriteLine(&quot;MoveToFirstChild = &quot; + nav.MoveToFirstChild.ToString); Console.WriteLine(&quot;Name = &quot; + nav.Name); Console.WriteLine(&quot;MoveToFirstNamespace = &quot;+ nav.MoveToFirstNamespace(XPathNamespaceScope.Local).ToString); Console.WriteLine(&quot;NodeType = &quot;+ nav.NodeType.ToString); Console.WriteLine(&quot;Name = &quot;+ nav.Name); Console.WriteLine(&quot;MoveToNextNamespace = &quot;+ nav.MoveToNextNamespace(XPathNamespaceScope.Local).ToString); Console.WriteLine(&quot;NodeType = &quot;+ nav.NodeType.ToString); Console.WriteLine(&quot;Name = &quot;+ nav.Name);

Console.WriteLine(&quot;\r\n\r\nExpected Results \r\n\r\n&quot;); nav.MoveToRoot; Console.WriteLine(&quot;MoveToFirstChild = &quot; + nav.MoveToFirstChild.ToString); Console.WriteLine(&quot;Name = &quot; + nav.Name); Console.WriteLine(&quot;MoveToFirstNamespace = &quot;+ nav.MoveToFirstNamespace.ToString); Console.WriteLine(&quot;NodeType = &quot;+ nav.NodeType.ToString); Console.WriteLine(&quot;Name = &quot;+ nav.Name); Console.WriteLine(&quot;MoveToNextNamespace = &quot;+ nav.MoveToNextNamespace.ToString); Console.WriteLine(&quot;NodeType = &quot;+ nav.NodeType.ToString); Console.WriteLine(&quot;Name = &quot;+ nav.Name);

}   } }                     Compile the project, and then set a breakpoint at the end of the Main function. On the Debug menu, click Start (or just press F5), and you should see the following output from the console window:

Checking navigator

MoveToFirstChild = True

Name = ns1:myElement

MoveToFirstNamespace = True

NodeType = Namespace

Name = ns2

MoveToNextNamespace = False

NodeType = Element

Name = ns1:myElement

Expected Results :

MoveToFirstChild = True

Name = ns1:myElement

MoveToFirstNamespace = True

NodeType = Namespace

Name = ns2

MoveToNextNamespace = True

NodeType = Namespace

Name = ns1

</li></ol>

The result returned by MoveToNextNamespace(XPathNamespaceScope.Local) is &quot;False&quot;, which is an incorrect result.

NOTE: The namespaces are stored in the reverse order in XMLDocument and XPathDocument. For example, if the XML data has namespaces in the order n1, n2, n3, the MoveToFirstNamespace method moves to n3, MoveToNextNamespace moves to n2, and so on.

Additional query words: XPathNavigator MoveToNextNamespace XPathNamespaceScope Local System.XML

Keywords: kbbug KB316808

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.