Microsoft KB Archive/317707

= BUG: XmlSchema Rearranges the Positions of Annotation and Include Elements =

Article ID: 317707

Article Last Modified on 2/12/2007

-

APPLIES TO


 * Microsoft .NET Framework Class Libraries 1.1
 * Microsoft .NET Framework Class Libraries 1.0

-



This article was previously published under Q317707



SYMPTOMS
XmlSchema rearranges the positions of xs:annotation and xs:include schema elements when those elements are intermingled in an XML schema so that all of the xs:include elements are brought to the beginning.



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



Steps to Reproduce the Behavior
  Paste the following code in a text file, and then save the file as C:\Q317707.xsd. Note that this schema contains several annotations intermingled with some includes that reference external schema files:    First child; annotation for xs:schema   Second child; annotation for xs:schema  <xs:include schemaLocation=&quot;Q317707External1.xsd&quot;>   Third child; annotation for the first xs:include element </xs:documentation> </xs:annotation> </xs:include>  Fourth child; annotation for xs:schema</xs:documentation> </xs:annotation> <xs:include schemaLocation=&quot;Q317707External2.xsd&quot;>   Fifth child; annotation for the second xs:include element </xs:documentation> </xs:annotation> </xs:include> <xs:element name=&quot;myElement1&quot;>  Sixth child; annotation for an element</xs:documentation> </xs:annotation> </xs:element> <xs:element name=&quot;myElement2&quot;/> </xs:schema> </li> <li> Paste the following two code sections in text files, and then save the files as C:\Q317707External1.xsd and C:\Q317707External2.xsd. These are the two external schema files that are referenced in the Q317707.xsd schema: <xs:schema xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns:myURN=&quot;urn:myURN&quot; > <xs:element name=&quot;test1&quot; type=&quot;xs:string&quot;/> </xs:schema> <xs:schema xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns:myURN=&quot;urn:myURN&quot; > <xs:element name=&quot;test2&quot; type=&quot;xs:string&quot;/> </xs:schema> </li> <li> In Microsoft Visual Studio .NET, create a new Visual C# Console Application project. Replace the original code in the Class1.cs file with the following code: using System; using System.Xml; using System.Xml.Schema;

namespace Q317707 {  public class Class1 {     // Event handler for handling compilation messages. public static void ValidationCallback(object sender, ValidationEventArgs args) {        Console.WriteLine(args.Message); }     public static void Main(string[] args) {        try {                 // Load the schema file. XmlTextReader tr = new XmlTextReader(&quot;c:\\Q317707.xsd&quot;); XmlSchema schema = XmlSchema.Read(tr, new ValidationEventHandler(ValidationCallback));

// Compile the Schema; no errors should occur during this step. schema.Compile(new ValidationEventHandler(ValidationCallback));

// Write out the schema which shows the rearrangement. schema.Write(Console.Out); Console.WriteLine; }        catch(XmlSchemaException schemaExcep) {            Console.WriteLine(schemaExcep.Message); }        catch(Exception excep) {            Console.WriteLine(excep); }     }   } }                    </li> <li> Compile and run the application. The output resembles the following: <?xml version=&quot;1.0&quot; encoding=&quot;IBM437&quot;?> <xs:schema xmlns:myURN=&quot;urn:myURN&quot; xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot;> <xs:include schemaLocation=&quot;Q317707External1.xsd&quot;>   Third child; annotation for the first xs:include element </xs:documentation> </xs:annotation> </xs:include> <xs:include schemaLocation=&quot;Q317707External2.xsd&quot;>   Fifth child; annotation for the second xs:include element </xs:documentation> </xs:annotation> </xs:include>  First child; annotation for xs:schema</xs:documentation> </xs:annotation>  Second child; annotation for xs:schema</xs:documentation> </xs:annotation> <xs:annotation> <xs:documentation>Fourth child; annotation for xs:schema</xs:documentation> </xs:annotation> <xs:element name=&quot;myElement1&quot;> <xs:annotation> <xs:documentation>Sixth child; annotation for an element</xs:documentation> </xs:annotation> </xs:element> <xs:element name=&quot;myElement2&quot; /> </xs:schema> Note that the sequence of the elements is changed and xs:include elements are located before the annotations. You expect the sequence to be the same as the sequence in the original schema file. </li></ol>

Keywords: kbbug kbpending KB317707

-

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

© Microsoft Corporation. All rights reserved.