Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ HandleColumn()

XmlElement System.Data.XmlTreeGen.HandleColumn ( DataColumn col,
XmlDocument dc,
XmlElement schema,
bool fWriteOrdinal )
inlinepackage

Definition at line 1240 of file XmlTreeGen.cs.

1241 {
1242 string localName = ((col.ColumnMapping != MappingType.Element) ? "attribute" : "element");
1243 XmlElement xmlElement = dc.CreateElement("xs", localName, "http://www.w3.org/2001/XMLSchema");
1244 xmlElement.SetAttribute("name", col.EncodedColumnName);
1245 if (col.Namespace.Length == 0)
1246 {
1247 DataTable table = col.Table;
1248 string text = FindTargetNamespace(table);
1249 if (col.Namespace != text)
1250 {
1251 xmlElement.SetAttribute("form", "unqualified");
1252 }
1253 }
1254 if (col.GetType() != typeof(DataColumn))
1255 {
1257 }
1258 else
1259 {
1261 }
1262 AddExtendedProperties(col._extendedProperties, xmlElement);
1264 if (col.ColumnMapping == MappingType.Hidden)
1265 {
1266 if (!col.AllowDBNull)
1267 {
1268 xmlElement.SetAttribute("AllowDBNull", "urn:schemas-microsoft-com:xml-msdata", "false");
1269 }
1270 if (!col.DefaultValueIsNull)
1271 {
1272 if (col.DataType == typeof(bool))
1273 {
1274 xmlElement.SetAttribute("DefaultValue", "urn:schemas-microsoft-com:xml-msdata", ((bool)col.DefaultValue) ? "true" : "false");
1275 }
1276 else
1277 {
1278 ValidateColumnMapping(col.DataType);
1279 xmlElement.SetAttribute("DefaultValue", "urn:schemas-microsoft-com:xml-msdata", col.ConvertObjectToXml(col.DefaultValue));
1280 }
1281 }
1282 }
1283 if (!col.DefaultValueIsNull && col.ColumnMapping != MappingType.Hidden)
1284 {
1285 ValidateColumnMapping(col.DataType);
1286 if (col.ColumnMapping == MappingType.Attribute && !col.AllowDBNull)
1287 {
1288 if (col.DataType == typeof(bool))
1289 {
1290 xmlElement.SetAttribute("DefaultValue", "urn:schemas-microsoft-com:xml-msdata", ((bool)col.DefaultValue) ? "true" : "false");
1291 }
1292 else
1293 {
1294 xmlElement.SetAttribute("DefaultValue", "urn:schemas-microsoft-com:xml-msdata", col.ConvertObjectToXml(col.DefaultValue));
1295 }
1296 }
1297 else if (col.DataType == typeof(bool))
1298 {
1299 xmlElement.SetAttribute("default", ((bool)col.DefaultValue) ? "true" : "false");
1300 }
1301 else if (!col.IsCustomType)
1302 {
1303 xmlElement.SetAttribute("default", col.ConvertObjectToXml(col.DefaultValue));
1304 }
1305 }
1306 if (_schFormat == SchemaFormat.Remoting)
1307 {
1308 xmlElement.SetAttribute("targetNamespace", "urn:schemas-microsoft-com:xml-msdata", col.Namespace);
1309 }
1310 else if (col.Namespace != (col.Table.TypeName.IsEmpty ? col.Table.Namespace : col.Table.TypeName.Namespace) && col.Namespace.Length != 0)
1311 {
1312 XmlElement schema2 = GetSchema(col.Namespace);
1313 if (FindTypeNode(schema2, col.EncodedColumnName) == null)
1314 {
1315 schema2.AppendChild(xmlElement);
1316 }
1317 xmlElement = _dc.CreateElement("xs", localName, "http://www.w3.org/2001/XMLSchema");
1318 xmlElement.SetAttribute("ref", _prefixes[col.Namespace]?.ToString() + ":" + col.EncodedColumnName);
1319 if (col.Table.Namespace != _ds.Namespace)
1320 {
1321 GetSchema(col.Table.Namespace);
1322 }
1323 }
1324 int num = ((!col.AllowDBNull) ? 1 : 0);
1325 if (col.ColumnMapping == MappingType.Attribute && num != 0)
1326 {
1327 xmlElement.SetAttribute("use", "required");
1328 }
1329 if (col.ColumnMapping == MappingType.Hidden)
1330 {
1331 xmlElement.SetAttribute("use", "prohibited");
1332 }
1333 else if (col.ColumnMapping != MappingType.Attribute && num != 1)
1334 {
1335 xmlElement.SetAttribute("minOccurs", num.ToString(CultureInfo.InvariantCulture));
1336 }
1337 if (col.ColumnMapping == MappingType.Element && fWriteOrdinal)
1338 {
1339 xmlElement.SetAttribute("Ordinal", "urn:schemas-microsoft-com:xml-msdata", col.Ordinal.ToString(CultureInfo.InvariantCulture));
1340 }
1341 return xmlElement;
1342 }
static void ValidateColumnMapping(Type columnType)
void HandleColumnType(DataColumn col, XmlDocument dc, XmlElement root, XmlElement schema)
XmlElement GetSchema(string NamespaceURI)
void AddXdoProperties(object instance, XmlElement root, XmlDocument xd)
Definition XmlTreeGen.cs:83
void AddColumnProperties(DataColumn col, XmlElement root)
readonly SchemaFormat _schFormat
Definition XmlTreeGen.cs:36
static void AddExtendedProperties(PropertyCollection props, XmlElement node)
Definition XmlTreeGen.cs:55
XmlElement FindTypeNode(XmlElement node, string strType)
string FindTargetNamespace(DataTable table)
static CultureInfo InvariantCulture
XmlElement CreateElement(string name)
virtual void SetAttribute(string name, string? value)

References System.Data.XmlTreeGen._dc, System.Data.XmlTreeGen._ds, System.Data.XmlTreeGen._prefixes, System.Data.XmlTreeGen._schFormat, System.Data.XmlTreeGen.AddColumnProperties(), System.Data.XmlTreeGen.AddExtendedProperties(), System.Data.XmlTreeGen.AddXdoProperties(), System.Xml.XmlDocument.CreateElement(), System.Xml.Dictionary, System.Data.XmlTreeGen.FindTargetNamespace(), System.Data.XmlTreeGen.FindTypeNode(), System.Data.XmlTreeGen.GetSchema(), System.Data.XmlTreeGen.HandleColumnType(), System.Globalization.CultureInfo.InvariantCulture, System.Data.DataSet.Namespace, System.Xml.XmlElement.SetAttribute(), System.text, and System.Data.XmlTreeGen.ValidateColumnMapping().

Referenced by System.Data.XmlTreeGen.HandleTable().