Microsoft KB Archive/317503

= BUG: Namespace &quot;xml&quot; is not reserved when using System.Xml =

Article ID: 317503

Article Last Modified on 2/12/2007

-

APPLIES TO


 * Microsoft Visual Studio .NET 2002 Professional Edition
 * Microsoft Visual Studio .NET 2003 Professional Edition
 * Microsoft .NET Framework Class Libraries 1.1
 * Microsoft .NET Framework Class Libraries 1.0

-



This article was previously published under Q317503



SYMPTOMS
If you use an XmlDocument(System.Xml namespace) call to create the xml:lang attribute on an element, the &quot;xml&quot; namespace prefix is not associated with http://www.w3.org/XML/1998/namespace as it needs to. For example, the following code XmlDocument x = new XmlDocument; XmlElement c = x.CreateElement(&quot;test&quot;); c.SetAttribute(&quot;xml:lang&quot;, &quot;en-US&quot;); x.AppendChild(c); Console.Out.WriteLine( &quot;'&quot; + x.DocumentElement.Attributes[0].NamespaceURI + &quot;'&quot; ); Console.Out.WriteLine( &quot;'&quot; + x.DocumentElement.Attributes[0].Prefix + &quot;'&quot;); produces the following output: '' 'xml' The expected output is as follows: 'http://www.w3.org/XML/1998/namespace' 'xml'



RESOLUTION
If you need to persist XML data, use the XmlTextWriter object to output the correct result. See the &quot;More Information&quot; section for sample code.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



MORE INFORMATION
According to the World Wide Web Consortium (W3C) specification (http://www.w3.org/TR/REC-xml-names/#xmlReserved), namespace prefixes beginning with the three-letter sequence x, m, l, in any case combination, are reserved for use by XML and XML-related specifications.

It is illegal to use &quot;xml&quot; as a prefix to create random elements or attributes other than xml:lang or xml:space. For example, it is illegal to create an attribute xml:this on the element &quot;that&quot; as follows: 

Steps to Reproduce Behavior
 Create a Microsoft C# console project.  Replace the code inside Class1.cs with the following: using System; using System.Xml;

namespace XMLTest1 {   ///     /// Summary description for Class1. ///    class Class1 {       static void Main(string[] args) {           XmlDocument x = new XmlDocument; XmlElement c = x.CreateElement(&quot;test&quot;); c.SetAttribute(&quot;xml:lang&quot;, &quot;en-us&quot;); x.AppendChild(c); Console.Out.WriteLine( &quot;'&quot; + x.DocumentElement.Attributes[0].NamespaceURI + &quot;'&quot; ); Console.Out.WriteLine( &quot;'&quot; + x.DocumentElement.Attributes[0].Prefix + &quot;'&quot;);

Console.Out.WriteLine(&quot;output from XmlDocument: &quot; + x.InnerXml); Console.Out.WriteLine(&quot;\noutput from XmlTextWriter: &quot;); XmlTextWriter writer = new XmlTextWriter(Console.Out); writer.Formatting = Formatting.Indented; x.WriteTo( writer ); writer.Flush; Console.WriteLine;

return; }   } }                      Compile and then run the project. The output is as follows: '' 'xml' output from XmlDocument: 

output from XmlTextWriter:  The XmlTextWriter writes the correct XML data. 

Keywords: kbvs2002sp1sweep kbbug kbpending KB317503

-

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

© Microsoft Corporation. All rights reserved.