System.Data.XmlSchemaWriter.WriteSchema C# (CSharp) Method

WriteSchema() public method

public WriteSchema ( ) : void
return void
		public void WriteSchema ()
		{
			ListDictionary names = new ListDictionary ();
			ListDictionary includes = new ListDictionary ();

			// Add namespaces used in DataSet components (tables, columns, ...)
			foreach (DataTable dt in tables) {
				foreach (DataColumn col in dt.Columns)
					CheckNamespace (col.Prefix, col.Namespace, names, includes);
				CheckNamespace (dt.Prefix, dt.Namespace, names, includes);
			}

			w.WriteStartElement ("xs", "schema", xmlnsxs);
			w.WriteAttributeString ("id", XmlHelper.Encode (dataSetName));

			if (dataSetNamespace != String.Empty) {
				w.WriteAttributeString ("targetNamespace",
					dataSetNamespace);
				w.WriteAttributeString (
					"xmlns",
					XmlConstants.TnsPrefix,
					XmlConstants.XmlnsNS,
					dataSetNamespace);
			}
			w.WriteAttributeString ("xmlns", dataSetNamespace);

			w.WriteAttributeString ("xmlns", "xs",
				XmlConstants.XmlnsNS, xmlnsxs);
			w.WriteAttributeString ("xmlns",
				XmlConstants.MsdataPrefix,
				XmlConstants.XmlnsNS,
				XmlConstants.MsdataNamespace);

			if (CheckExtendedPropertyExists (tables, relations))
				w.WriteAttributeString ("xmlns",
					XmlConstants.MspropPrefix,
					XmlConstants.XmlnsNS,
					XmlConstants.MspropNamespace);

			if (dataSetNamespace != String.Empty) {
				w.WriteAttributeString ("attributeFormDefault", "qualified");
				w.WriteAttributeString ("elementFormDefault", "qualified");
			}

			foreach (string prefix in names.Keys)
				w.WriteAttributeString ("xmlns", prefix,
					XmlConstants.XmlnsNS,
					names [prefix] as string);

			if (includes.Count > 0)
				w.WriteComment ("ATTENTION: This schema contains references to other imported schemas");
			foreach (string ns in includes.Keys) {
				w.WriteStartElement ("xs", "import", xmlnsxs);
				w.WriteAttributeString ("namespace", ns);
				w.WriteAttributeString ("schemaLocation", includes [ns] as string);
				w.WriteEndElement ();
			}
			
			foreach (DataTable table in tables) {
				bool isTopLevel = true;
				foreach (DataRelation rel in table.ParentRelations) {
					if (rel.Nested) {
						isTopLevel = false;
						break;
					}
				}
				// LAMESPEC: You have a nested relationship but only one table, 
				// write table element first
				if (!isTopLevel && tables.Length < 2)
						WriteTableElement (table);
			}
	
			WriteDataSetElement ();

			w.WriteEndElement (); // xs:schema

			w.Flush ();
		}