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 ());
103 public XmlSchema Add (string ns, XmlReader reader, XmlResolver resolver)
105 internal XmlSchema Add (string ns, XmlReader reader, XmlResolver resolver)
108 XmlSchema schema = XmlSchema.Read (reader, ValidationEventHandler);
109 if (schema.TargetNamespace == null)
110 schema.TargetNamespace = ns;
111 else if (ns != null && schema.TargetNamespace != ns)
112 throw new XmlSchemaException ("The actual targetNamespace in the schema does not match the parameter.");
117 public XmlSchema Add (string ns, string uri)
119 XmlReader reader = new XmlTextReader (uri);
121 return Add (ns, reader);
127 public XmlSchema Add (XmlSchema schema)
129 return Add (schema, new XmlUrlResolver ());
132 public XmlSchema Add (XmlSchema schema, XmlResolver resolver)
135 throw new ArgumentNullException ("schema");
137 XmlSchemaSet xss = new XmlSchemaSet (schemaSet.NameTable);
140 // FIXME: maybe it requires Reprocess()
142 xss.ValidationEventHandler += ValidationEventHandler;
143 xss.XmlResolver = resolver;
147 // It is set only when the compilation was successful.
152 public void Add (XmlSchemaCollection schema)
155 throw new ArgumentNullException ("schema");
157 XmlSchemaSet xss = new XmlSchemaSet (schemaSet.NameTable);
160 // FIXME: maybe it requires Reprocess()
161 xss.Add (schema.schemaSet);
162 xss.ValidationEventHandler += ValidationEventHandler;
163 xss.XmlResolver = schemaSet.XmlResolver;
167 // It is set only when the compilation was successful.
171 public bool Contains (string ns)
174 return schemaSet.Contains (ns);
178 public bool Contains (XmlSchema schema)
181 return schemaSet.Contains (schema);
185 public void CopyTo (XmlSchema[] array, int index)
188 schemaSet.CopyTo (array, index);
192 public XmlSchemaCollectionEnumerator GetEnumerator ()
194 // The actual collection is schemaSet.Schemas()
195 return new XmlSchemaCollectionEnumerator(schemaSet.Schemas());
198 int ICollection.Count {
199 get { return Count; }
203 void ICollection.CopyTo (Array array, int index)
206 schemaSet.CopyTo (array, index);
210 bool ICollection.IsSynchronized
212 get { return true; } // always
215 IEnumerator IEnumerable.GetEnumerator ()
217 return this.GetEnumerator ();
220 Object ICollection.SyncRoot
225 void OnValidationError (object o, ValidationEventArgs e)
227 if (ValidationEventHandler != null)
228 ValidationEventHandler (o, e);
229 else if (e.Severity == XmlSeverityType.Error)