2 // System.Xml.Schema.XmlSchemaCollection.cs
5 // Dwivedi, Ajay kumar Adwiv@Yahoo.com
6 // Atsushi Enomoto ginga@kit.hi-ho.ne.jp
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System.Collections;
34 namespace System.Xml.Schema
37 /// Summary description for XmlSchemaCollection.
39 /// It is just a wrapper for XmlSchemaSet (unlike MS.NET, our
40 /// XmlSchemaCollection is originally designed to be conformant to
41 /// W3C specification).
44 [Obsolete ("Use XmlSchemaSet.")]
46 public sealed class XmlSchemaCollection : ICollection, IEnumerable
49 private XmlSchemaSet schemaSet;
51 public XmlSchemaCollection ()
52 : this (new NameTable ())
56 public XmlSchemaCollection (XmlNameTable nameTable)
57 : this (new XmlSchemaSet (nameTable))
61 internal XmlSchemaCollection (XmlSchemaSet schemaSet)
63 this.schemaSet = schemaSet;
67 internal XmlSchemaSet SchemaSet {
68 get { return schemaSet; }
72 get { return schemaSet.Count; }
75 public XmlNameTable NameTable {
76 get { return schemaSet.NameTable; }
79 public XmlSchema this [ string ns ] {
81 ICollection col = schemaSet.Schemas (ns);
84 IEnumerator e = col.GetEnumerator ();
86 return (XmlSchema) e.Current;
93 public event ValidationEventHandler ValidationEventHandler;
96 public XmlSchema Add (string ns, XmlReader reader)
98 return Add (ns, reader, new XmlUrlResolver ());
102 public XmlSchema Add (string ns, XmlReader reader, XmlResolver resolver)
104 internal XmlSchema Add (string ns, XmlReader reader, XmlResolver resolver)
107 XmlSchema schema = XmlSchema.Read (reader, ValidationEventHandler);
108 schema.Compile (ValidationEventHandler, schemaSet, resolver);
110 return schemaSet.Add (schema);
114 public XmlSchema Add (string ns, string uri)
117 return schemaSet.Add (ns, uri);
121 public XmlSchema Add (XmlSchema schema)
123 return Add (schema, new XmlUrlResolver ());
126 public XmlSchema Add (XmlSchema schema, XmlResolver resolver)
129 throw new ArgumentNullException ("schema");
131 // XmlSchemaCollection.Add() compiles, while XmlSchemaSet.Add() does not
132 if (!schema.IsCompiled)
133 schema.Compile (ValidationEventHandler, schemaSet, resolver);
134 // compilation error -> returns null (and don't add to the collection).
135 if (!schema.IsCompiled)
139 // consider imported schemas.
140 schemaSet.Add (schema.Schemas);
145 public void Add (XmlSchemaCollection schema)
148 throw new ArgumentNullException ("schema");
151 schemaSet.Add (schema.schemaSet);
155 public bool Contains (string ns)
158 return schemaSet.Contains (ns);
162 public bool Contains (XmlSchema schema)
165 return schemaSet.Contains (schema);
169 public void CopyTo (XmlSchema[] array, int index)
172 schemaSet.CopyTo (array, index);
176 public XmlSchemaCollectionEnumerator GetEnumerator ()
178 // The actual collection is schemaSet.Schemas()
179 return new XmlSchemaCollectionEnumerator(schemaSet.Schemas());
182 int ICollection.Count {
183 get { return Count; }
187 void ICollection.CopyTo (Array array, int index)
190 schemaSet.CopyTo (array, index);
194 bool ICollection.IsSynchronized
196 get { return true; } // always
199 IEnumerator IEnumerable.GetEnumerator ()
201 return this.GetEnumerator ();
204 Object ICollection.SyncRoot
209 internal void OnValidationError (object o, ValidationEventArgs e)
211 if (ValidationEventHandler != null)
212 ValidationEventHandler (o, e);
213 else if (e.Severity == XmlSeverityType.Error)