System.Data.XmlSchemaDataImporter.Process C# (CSharp) Метод

Process() публичный Метод

public Process ( ) : void
Результат void
		public void Process ()
		{
			if (schema.Id != null)
				dataset.DataSetName = schema.Id; // default. Overridable by "DataSet element"
			dataset.Namespace = schema.TargetNamespace;

			// Find dataset element
			foreach (XmlSchemaObject obj in schema.Items) {
				XmlSchemaElement el = obj as XmlSchemaElement;
				if (el != null) {
					if (datasetElement == null &&
						IsDataSetElement (el))
						datasetElement = el;
#if NET_2_0
					if (el.ElementSchemaType is XmlSchemaComplexType &&
					    el.ElementSchemaType != schemaAnyType)
#else
					if (el.ElementType is XmlSchemaComplexType &&
					    el.ElementType != schemaAnyType)
#endif
						targetElements.Add (obj);
				}
			}

			// make reservation of identity constraints
			if (datasetElement != null) {
				// keys/uniques.
				foreach (XmlSchemaObject obj in datasetElement.Constraints)
					if (! (obj is XmlSchemaKeyref))
						ReserveSelfIdentity ((XmlSchemaIdentityConstraint) obj);
				// keyrefs.
				foreach (XmlSchemaObject obj in datasetElement.Constraints)
					if (obj is XmlSchemaKeyref)
						ReserveRelationIdentity (datasetElement, (XmlSchemaKeyref) obj);
			}

			foreach (XmlSchemaObject obj in schema.Items) {
				if (obj is XmlSchemaElement) {
					XmlSchemaElement el = obj as XmlSchemaElement;
#if NET_2_0
					if (el.ElementSchemaType is XmlSchemaComplexType &&
					    el.ElementSchemaType != schemaAnyType)
#else
					if (el.ElementType is XmlSchemaComplexType &&
					    el.ElementType != schemaAnyType)
#endif
						targetElements.Add (obj);
				}
			}

			// This collection will grow up while processing elements.
			int globalElementCount = targetElements.Count;

			for (int i = 0; i < globalElementCount; i++)
				ProcessGlobalElement ((XmlSchemaElement) targetElements [i]);

			// Rest are local elements.
			for (int i = globalElementCount; i < targetElements.Count; i++)
				ProcessDataTableElement ((XmlSchemaElement) targetElements [i]);

			// Handle relation definitions written as xs:annotation.
			// See detail: http://msdn.microsoft.com/library/shared/happyUrl/fnf_msdn.asp?Redirect=%22http://msdn.microsoft.com/404/default.asp%22
			foreach (XmlSchemaObject obj in schema.Items)
				if (obj is XmlSchemaAnnotation)
					HandleAnnotations ((XmlSchemaAnnotation) obj, false);

			if (datasetElement != null) {
				// Handle constraints in the DataSet element. First keys.
				foreach (XmlSchemaObject obj in datasetElement.Constraints)
					if (! (obj is XmlSchemaKeyref))
						ProcessSelfIdentity (reservedConstraints [obj] as ConstraintStructure);
				// Then keyrefs.
				foreach (XmlSchemaObject obj in datasetElement.Constraints)
					if (obj is XmlSchemaKeyref)
						ProcessRelationIdentity (datasetElement, reservedConstraints [obj] as ConstraintStructure);
			}

			foreach (RelationStructure rs in this.relations)
				dataset.Relations.Add (GenerateRelationship (rs));
		}

Usage Example

Пример #1
0
		public void ReadXmlSchema (XmlReader reader)
		{
#if true
			XmlSchemaDataImporter xsdImporter = new XmlSchemaDataImporter (this, reader, true);
			xsdImporter.Process ();
			tableAdapterSchemaInfo = xsdImporter.CurrentAdapter;
#else
			XmlSchemaMapper SchemaMapper = new XmlSchemaMapper (this);
			SchemaMapper.Read (reader);
#endif
		}