System.Data.XmlDataInferenceLoader.InferTableElement C# (CSharp) Method

InferTableElement() private method

private InferTableElement ( TableMapping parentTable, XmlElement el ) : void
parentTable TableMapping
el System.Xml.XmlElement
return void
		private void InferTableElement (TableMapping parentTable, XmlElement el)
		{
			// If parent table already has the same name column but
			// mapped as Element, that must be removed.
			// FIXME: This can be done later (doing it here is
			// loss of performance.
			CheckExtraneousElementColumn (parentTable, el);

			string localName = XmlHelper.Decode (el.LocalName);
			TableMapping table = GetMappedTable (parentTable, localName, el.NamespaceURI);

			bool hasChildElements = false;
			bool hasAttributes = false;
			bool hasText = false;
			bool isElementRepeated = false;

			foreach (XmlAttribute attr in el.Attributes) {
				if (attr.NamespaceURI == XmlConstants.XmlnsNS
#if NET_2_0
					|| attr.NamespaceURI == XmlConstants.XmlNS
#endif
					)
					continue;
				if (ignoredNamespaces != null &&
					ignoredNamespaces.Contains (attr.NamespaceURI))
					continue;

				hasAttributes = true;
				DataColumn col = GetMappedColumn (table,
					XmlHelper.Decode (attr.LocalName),
					attr.Prefix,
					attr.NamespaceURI,
					MappingType.Attribute,
					null);
			}

			foreach (XmlNode n in el.ChildNodes) {
				switch (n.NodeType) {
				case XmlNodeType.Comment:
				case XmlNodeType.ProcessingInstruction: // ignore
					continue;
				default: // text content
					hasText = true;
					if (GetElementMappingType (el, ignoredNamespaces, null) == ElementMappingType.Repeated)
						isElementRepeated = true;
					break;
				case XmlNodeType.Element: // child
					hasChildElements = true;
					XmlElement cel = n as XmlElement;
					string childLocalName = XmlHelper.Decode (cel.LocalName);

					switch (GetElementMappingType (cel, ignoredNamespaces, null)) {
					case ElementMappingType.Simple:
						InferColumnElement (table, cel);
						break;
					case ElementMappingType.Repeated:
						if (table.PrimaryKey == null)
							PopulatePrimaryKey (table);
						PopulateRelationStructure (table.Table.TableName, childLocalName, table.PrimaryKey.ColumnName);
						InferRepeatedElement (table, cel);
						break;
					case ElementMappingType.Complex:
						if (table.PrimaryKey == null)
							PopulatePrimaryKey (table);
						PopulateRelationStructure (table.Table.TableName, childLocalName, table.PrimaryKey.ColumnName);
						InferTableElement (table, cel);
						break;
					}
					break;
				}
			}

			// Attributes + !Children + Text = SimpleContent
			if (table.SimpleContent == null // no need to create
				&& !hasChildElements && hasText && (hasAttributes || isElementRepeated)) {
				GetMappedColumn (table, table.Table.TableName + "_Text", String.Empty, String.Empty, MappingType.SimpleContent, null);
			}
		}