/// XmlSchemaCollection is originally designed to be conformant to
/// W3C specification).
/// </summary>
+#if NET_2_0
+ [Obsolete ("Use XmlSchemaSet.")]
+#endif
public sealed class XmlSchemaCollection : ICollection, IEnumerable
{
//private fields
public XmlSchemaCollection (XmlNameTable nameTable)
: this (new XmlSchemaSet (nameTable))
{
- this.schemaSet.SchemaCollection = this;
+ schemaSet.ValidationEventHandler += new ValidationEventHandler (OnValidationError);
}
internal XmlSchemaCollection (XmlSchemaSet schemaSet)
}
public XmlSchema this [ string ns ] {
- get { return schemaSet.Get (ns); }
+ get {
+ ICollection col = schemaSet.Schemas (ns);
+ if (col == null)
+ return null;
+ IEnumerator e = col.GetEnumerator ();
+ if (e.MoveNext ())
+ return (XmlSchema) e.Current;
+ else
+ return null;
+ }
}
// Events
return Add (ns, reader, new XmlUrlResolver ());
}
-#if NET_1_0
- internal XmlSchema Add (string ns, XmlReader reader, XmlResolver resolver)
-#else
public XmlSchema Add (string ns, XmlReader reader, XmlResolver resolver)
-#endif
{
XmlSchema schema = XmlSchema.Read (reader, ValidationEventHandler);
- schema.Compile (ValidationEventHandler, this, resolver);
- lock (schemaSet) {
- return schemaSet.Add (schema);
- }
+ if (schema.TargetNamespace == null)
+ schema.TargetNamespace = ns;
+ else if (ns != null && schema.TargetNamespace != ns)
+ throw new XmlSchemaException ("The actual targetNamespace in the schema does not match the parameter.");
+
+ return Add (schema);
}
public XmlSchema Add (string ns, string uri)
{
- lock (schemaSet) {
- return schemaSet.Add (ns, uri);
+ XmlReader reader = new XmlTextReader (uri);
+ try {
+ return Add (ns, reader);
+ } finally {
+ reader.Close ();
}
}
if (schema == null)
throw new ArgumentNullException ("schema");
- // XmlSchemaCollection.Add() compiles, while XmlSchemaSet.Add() does not
- if (!schema.IsCompiled)
- schema.Compile (ValidationEventHandler, this, resolver);
+ XmlSchemaSet xss = new XmlSchemaSet (schemaSet.NameTable);
+ xss.Add (schemaSet);
- string ns = GetSafeNs (schema.TargetNamespace);
- lock (schemaSet) {
- if (schemaSet.Contains (ns))
- schemaSet.Remove (schemaSet.Get (ns));
- return schemaSet.Add (schema);
- }
- }
-
- private string GetSafeNs (string ns)
- {
- return ns != null ? ns : String.Empty;
+ // FIXME: maybe it requires Reprocess()
+ xss.Add (schema);
+ xss.ValidationEventHandler += ValidationEventHandler;
+ xss.XmlResolver = resolver;
+ xss.Compile ();
+ if (!xss.IsCompiled)
+ return null;
+ // It is set only when the compilation was successful.
+ schemaSet = xss;
+ return schema;
}
public void Add (XmlSchemaCollection schema)
if (schema == null)
throw new ArgumentNullException ("schema");
- /*
- foreach (XmlSchema s in schema) {
- string ns = GetSafeNs (s.TargetNamespace);
- lock (schemaSet) {
- if (schemaSet.Contains (ns))
- schemaSet.Remove (schemaSet.Get (ns));
- schemaSet.Add (s);
- }
- }
- */
- lock (schemaSet) {
- schemaSet.Add (schema.schemaSet);
- }
+ XmlSchemaSet xss = new XmlSchemaSet (schemaSet.NameTable);
+ xss.Add (schemaSet);
+
+ // FIXME: maybe it requires Reprocess()
+ xss.Add (schema.schemaSet);
+ xss.ValidationEventHandler += ValidationEventHandler;
+ xss.XmlResolver = schemaSet.XmlResolver;
+ xss.Compile ();
+ if (!xss.IsCompiled)
+ return;
+ // It is set only when the compilation was successful.
+ schemaSet = xss;
}
public bool Contains (string ns)
public XmlSchemaCollectionEnumerator GetEnumerator ()
{
- return new XmlSchemaCollectionEnumerator (this);
+ // The actual collection is schemaSet.Schemas()
+ return new XmlSchemaCollectionEnumerator(schemaSet.Schemas());
+ }
+
+ int ICollection.Count {
+ get { return Count; }
}
-
+
// interface Methods
void ICollection.CopyTo (Array array, int index)
{
IEnumerator IEnumerable.GetEnumerator ()
{
- return schemaSet.GetEnumerator ();
+ return this.GetEnumerator ();
}
Object ICollection.SyncRoot
get { return this; }
}
- // Internal Methods
- internal XmlSchemaAttribute FindAttribute (XmlQualifiedName qname)
- {
- return (XmlSchemaAttribute) schemaSet.GlobalAttributes [qname];
- }
-
- internal XmlSchemaElement FindElement (XmlQualifiedName qname)
- {
- return (XmlSchemaElement) schemaSet.GlobalElements [qname];
- }
-
- internal object FindSchemaType (XmlQualifiedName qname)
- {
- return schemaSet.GlobalTypes [qname];
- }
-
- internal void OnValidationError (object o, ValidationEventArgs e)
+ void OnValidationError (object o, ValidationEventArgs e)
{
if (ValidationEventHandler != null)
ValidationEventHandler (o, e);