2 // System.Xml.Serialization.XmlSchemas
\r
5 // Tim Coleman (tim@timcoleman.com)
\r
7 // Copyright (C) Tim Coleman, 2002
\r
10 using System.Collections;
\r
11 using System.Xml.Schema;
\r
13 namespace System.Xml.Serialization {
\r
14 public class XmlSchemas : CollectionBase {
\r
17 private static string msdataNS = "urn:schemas-microsoft-com:xml-msdata";
\r
19 Hashtable table = new Hashtable ();
\r
23 #region Constructors
\r
25 public XmlSchemas ()
\r
29 #endregion // Constructors
\r
33 public XmlSchema this [int index] {
\r
35 if (index < 0 || index > Count)
\r
36 throw new ArgumentOutOfRangeException ();
\r
38 return (XmlSchema) List [index];
\r
40 set { List [index] = value; }
\r
43 public XmlSchema this [string ns] {
\r
44 get { return (XmlSchema) table[ns!=null?ns:""]; }
\r
47 #endregion // Properties
\r
51 public int Add (XmlSchema schema)
\r
53 Insert (Count, schema);
\r
57 public void Add (XmlSchemas schemas)
\r
59 foreach (XmlSchema schema in schemas)
\r
63 public bool Contains (XmlSchema schema)
\r
65 return List.Contains (schema);
\r
68 public void CopyTo (XmlSchema[] array, int index)
\r
70 List.CopyTo (array, index);
\r
73 public object Find (XmlQualifiedName name, Type type)
\r
75 XmlSchema schema = table [name.Namespace] as XmlSchema;
\r
79 if (!schema.IsCompiled) {
\r
80 schema.Compile (null);
\r
83 XmlSchemaObjectTable tbl = null;
\r
85 if (type == typeof (XmlSchemaSimpleType) || type == typeof (XmlSchemaComplexType))
\r
86 tbl = schema.SchemaTypes;
\r
87 else if (type == typeof (XmlSchemaAttribute))
\r
88 tbl = schema.Attributes;
\r
89 else if (type == typeof (XmlSchemaAttributeGroup))
\r
90 tbl = schema.AttributeGroups;
\r
91 else if (type == typeof (XmlSchemaElement))
\r
92 tbl = schema.Elements;
\r
93 else if (type == typeof (XmlSchemaGroup))
\r
94 tbl = schema.Groups;
\r
95 else if (type == typeof (XmlSchemaNotation))
\r
96 tbl = schema.Notations;
\r
98 object res = (tbl != null) ? tbl [name] : null;
\r
99 if (res != null && res.GetType () != type) return null;
\r
103 public int IndexOf (XmlSchema schema)
\r
105 return List.IndexOf (schema);
\r
108 public void Insert (int index, XmlSchema schema)
\r
110 List.Insert (index, schema);
\r
113 public static bool IsDataSet (XmlSchema schema)
\r
115 XmlSchemaElement el = schema.Items.Count == 1 ?
\r
116 schema.Items [0] as XmlSchemaElement : null;
\r
117 if (el != null && el.UnhandledAttributes.Length > 0) {
\r
118 for (int i = 0; i < el.UnhandledAttributes.Length; i++) {
\r
119 XmlAttribute attr = el.UnhandledAttributes [i];
\r
120 if (attr.NamespaceURI == msdataNS && attr.LocalName == "IsDataSet")
\r
121 return (attr.Value.ToLower (System.Globalization.CultureInfo.InvariantCulture) == "true");
\r
127 protected override void OnClear ()
\r
132 protected override void OnInsert (int index, object value)
\r
134 string ns = ((XmlSchema) value).TargetNamespace;
\r
135 if (ns == null) ns = "";
\r
136 table [ns] = value;
\r
139 protected override void OnRemove (int index, object value)
\r
141 table.Remove (value);
\r
144 protected override void OnSet (int index, object oldValue, object newValue)
\r
146 string ns = ((XmlSchema) oldValue).TargetNamespace;
\r
147 if (ns == null) ns = "";
\r
148 table [ns] = newValue;
\r
151 public void Remove (XmlSchema schema)
\r
153 List.Remove (schema);
\r
156 #endregion // Methods
\r