2005-06-21 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / System.XML / System.Xml.Schema / XmlSchema.cs
index 005f76ebe68ff1762747bb8ddb5023e838cc58a7..636695f56f74a55389b2166c262c6a7bc12ad40a 100755 (executable)
@@ -63,7 +63,6 @@ namespace System.Xml.Schema
                private string targetNamespace ;
                private XmlAttribute[] unhandledAttributes ;
                private string version;
-               private string language;
 
                // other post schema compilation infoset
                private Hashtable idCollection;
@@ -267,7 +266,6 @@ namespace System.Xml.Schema
                ///             3. id must be of type ID
                ///             4. targetNamespace should be any uri
                ///             5. version should be a normalizedString
-               ///             6. xml:lang should be a language
                /// </remarks>
                public void Compile (ValidationEventHandler handler)
                {
@@ -341,19 +339,24 @@ namespace System.Xml.Schema
                        if (!XmlSchemaUtil.CheckNormalizedString(Version))
                                error(handler, Version + "is not a valid value for version attribute of schema");
 
-                       //6. xml:lang must be a language (removed)
-
                        // Compile the content of this schema
 
                        compilationItems = new XmlSchemaObjectCollection ();
-                       for (int i = 0; i < Items.Count; i++)
+                       for (int i = 0; i < Items.Count; i++) {
+#if NET_2_0
+                               Items [i].Parent = this;
+#endif
                                compilationItems.Add (Items [i]);
+                       }
                        if (this == rootSchema)
                                handledUris = new Hashtable ();
 
                        // First, we run into inclusion schemas to collect 
                        // compilation target items into compiledItems.
                        for (int i = 0; i < Includes.Count; i++) {
+#if NET_2_0
+                               Includes [i].Parent = this;
+#endif
                                XmlSchemaExternal ext = Includes [i] as XmlSchemaExternal;
                                if (ext == null) {
                                        error (handler, String.Format ("Object of Type {0} is not valid in Includes Property of XmlSchema", Includes [i].GetType().Name));
@@ -575,7 +578,8 @@ namespace System.Xml.Schema
                        Uri baseUri = null;
                        if (this.SourceUri != null && this.SourceUri != String.Empty)
                                baseUri = new Uri (this.SourceUri);
-                       return resolver.ResolveUri (baseUri, relativeUri).ToString ();
+                       Uri abs = resolver.ResolveUri (baseUri, relativeUri);
+                       return abs != null ? abs.ToString () : String.Empty;
                }
 
                internal bool IsNamespaceAbsent (string ns)
@@ -712,9 +716,6 @@ namespace System.Xml.Schema
                                        case "version":
                                                schema.version = reader.Value;
                                                break;
-                                       case "xml:lang":
-                                               schema.language = reader.Value;
-                                               break;
                                        default:
                                                if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                                                        error(h, reader.Name + " attribute is not allowed in schema element",null);
@@ -870,8 +871,6 @@ namespace System.Xml.Schema
                        XmlSerializerNamespaces nss = new XmlSerializerNamespaces ();
 
                        if (namespaceManager != null) {
-                               if (nss == null)
-                                       nss = new XmlSerializerNamespaces ();
                                foreach (string name in namespaceManager) {
                                        //xml and xmlns namespaces are added by default in namespaceManager.
                                        //So we should ignore them
@@ -881,10 +880,21 @@ namespace System.Xml.Schema
                        }
 
                        if (Namespaces != null && Namespaces.Count > 0) {
-                               nss.Add (String.Empty, XmlSchema.Namespace);
-                               foreach (XmlQualifiedName qn in Namespaces.ToArray ()) {
+                               XmlQualifiedName [] qnames = Namespaces.ToArray ();
+                               foreach (XmlQualifiedName qn in qnames)
                                        nss.Add (qn.Name, qn.Namespace);
+                               string p = String.Empty;
+                               bool loop = true;
+                               for (int idx = 1; loop; idx++) {
+                                       loop = false;
+                                       foreach (XmlQualifiedName qn in qnames)
+                                               if (qn.Name == p) {
+                                                       p = "q" + idx;
+                                                       loop = true;
+                                                       break;
+                                               }
                                }
+                               nss.Add (p, XmlSchema.Namespace);
                        }
 
                        if (nss.Count == 0) {
@@ -896,7 +906,13 @@ namespace System.Xml.Schema
                        }
 
                        XmlSchemaSerializer xser = new XmlSchemaSerializer ();
-                       xser.Serialize (writer, this, nss);
+                       XmlSerializerNamespaces backup = Namespaces;
+                       try {
+                               Namespaces = null;
+                               xser.Serialize (writer, this, nss);
+                       } finally {
+                               Namespaces = backup;
+                       }
                        writer.Flush();
                }
                #endregion