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))
59 schemaSet.ValidationEventHandler += new ValidationEventHandler (OnValidationError);
62 internal XmlSchemaCollection (XmlSchemaSet schemaSet)
64 this.schemaSet = schemaSet;
68 internal XmlSchemaSet SchemaSet {
69 get { return schemaSet; }
73 get { return schemaSet.Count; }
76 public XmlNameTable NameTable {
77 get { return schemaSet.NameTable; }
80 public XmlSchema this [ string ns ] {
82 ICollection col = schemaSet.Schemas (ns);
85 IEnumerator e = col.GetEnumerator ();
87 return (XmlSchema) e.Current;
94 public event ValidationEventHandler ValidationEventHandler;
97 public XmlSchema Add (string ns, XmlReader reader)
99 return Add (ns, reader, new XmlUrlResolver ());
102 public XmlSchema Add (string ns, XmlReader reader, XmlResolver resolver)
104 XmlSchema schema = XmlSchema.Read (reader, ValidationEventHandler);
105 if (schema.TargetNamespace == null)
106 schema.TargetNamespace = ns;
107 else if (ns != null && schema.TargetNamespace != ns)
108 throw new XmlSchemaException ("The actual targetNamespace in the schema does not match the parameter.");
113 public XmlSchema Add (string ns, string uri)
115 XmlReader reader = new XmlTextReader (uri);
117 return Add (ns, reader);
123 public XmlSchema Add (XmlSchema schema)
125 return Add (schema, new XmlUrlResolver ());
128 public XmlSchema Add (XmlSchema schema, XmlResolver resolver)
131 throw new ArgumentNullException ("schema");
133 XmlSchemaSet xss = new XmlSchemaSet (schemaSet.NameTable);
136 // FIXME: maybe it requires Reprocess()
138 xss.ValidationEventHandler += ValidationEventHandler;
139 xss.XmlResolver = resolver;
143 // It is set only when the compilation was successful.
148 public void Add (XmlSchemaCollection schema)
151 throw new ArgumentNullException ("schema");
153 XmlSchemaSet xss = new XmlSchemaSet (schemaSet.NameTable);
156 // FIXME: maybe it requires Reprocess()
157 xss.Add (schema.schemaSet);
158 xss.ValidationEventHandler += ValidationEventHandler;
159 xss.XmlResolver = schemaSet.XmlResolver;
163 // It is set only when the compilation was successful.
167 public bool Contains (string ns)
170 return schemaSet.Contains (ns);
174 public bool Contains (XmlSchema schema)
177 return schemaSet.Contains (schema);
181 public void CopyTo (XmlSchema[] array, int index)
184 schemaSet.CopyTo (array, index);
188 public XmlSchemaCollectionEnumerator GetEnumerator ()
190 // The actual collection is schemaSet.Schemas()
191 return new XmlSchemaCollectionEnumerator(schemaSet.Schemas());
194 int ICollection.Count {
195 get { return Count; }
199 void ICollection.CopyTo (Array array, int index)
202 schemaSet.CopyTo (array, index);
206 bool ICollection.IsSynchronized
208 get { return true; } // always
211 IEnumerator IEnumerable.GetEnumerator ()
213 return this.GetEnumerator ();
216 Object ICollection.SyncRoot
221 void OnValidationError (object o, ValidationEventArgs e)
223 if (ValidationEventHandler != null)
224 ValidationEventHandler (o, e);
225 else if (e.Severity == XmlSeverityType.Error)