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

◆ ReadXml() [6/7]

XmlReadMode System.Data.DataTable.ReadXml ( XmlReader reader,
XmlReadMode mode,
bool denyResolving )
inlinepackageinherited

Definition at line 5266 of file DataTable.cs.

5267 {
5268 IDisposable disposable = null;
5269 RowDiffIdUsageSection rowDiffIdUsageSection = default(RowDiffIdUsageSection);
5270 try
5271 {
5272 disposable = TypeLimiter.EnterRestrictedScope(this);
5273 bool flag = false;
5274 bool flag2 = false;
5275 bool isXdr = false;
5276 int depth = -1;
5277 XmlReadMode result = mode;
5278 rowDiffIdUsageSection.Prepare(this);
5279 if (reader == null)
5280 {
5281 return result;
5282 }
5283 bool flag3 = false;
5284 if (DataSet != null)
5285 {
5288 }
5289 else
5290 {
5292 EnforceConstraints = false;
5293 }
5294 if (reader is XmlTextReader)
5295 {
5296 ((XmlTextReader)reader).WhitespaceHandling = WhitespaceHandling.Significant;
5297 }
5299 if (mode != XmlReadMode.Fragment && reader.NodeType == XmlNodeType.Element)
5300 {
5301 depth = reader.Depth;
5302 }
5303 reader.MoveToContent();
5304 if (Columns.Count == 0 && IsEmptyXml(reader))
5305 {
5306 reader.Read();
5307 return result;
5308 }
5309 XmlDataLoader xmlDataLoader = null;
5310 if (reader.NodeType == XmlNodeType.Element)
5311 {
5312 XmlElement xmlElement = null;
5313 if (mode == XmlReadMode.Fragment)
5314 {
5315 xmlDocument.AppendChild(xmlDocument.CreateElement("ds_sqlXmlWraPPeR"));
5316 xmlElement = xmlDocument.DocumentElement;
5317 }
5318 else
5319 {
5320 if (reader.LocalName == "diffgram" && reader.NamespaceURI == "urn:schemas-microsoft-com:xml-diffgram-v1")
5321 {
5322 if (mode == XmlReadMode.DiffGram || mode == XmlReadMode.IgnoreSchema)
5323 {
5324 if (Columns.Count == 0)
5325 {
5326 if (reader.IsEmptyElement)
5327 {
5328 reader.Read();
5329 return XmlReadMode.DiffGram;
5330 }
5331 throw ExceptionBuilder.DataTableInferenceNotSupported();
5332 }
5333 ReadXmlDiffgram(reader);
5334 ReadEndElement(reader);
5335 }
5336 else
5337 {
5338 reader.Skip();
5339 }
5341 return result;
5342 }
5343 if (reader.LocalName == "Schema" && reader.NamespaceURI == "urn:schemas-microsoft-com:xml-data")
5344 {
5345 if (mode != XmlReadMode.IgnoreSchema && mode != XmlReadMode.InferSchema)
5346 {
5347 ReadXDRSchema(reader);
5348 }
5349 else
5350 {
5351 reader.Skip();
5352 }
5354 return result;
5355 }
5356 if (reader.LocalName == "schema" && reader.NamespaceURI == "http://www.w3.org/2001/XMLSchema")
5357 {
5358 if (mode != XmlReadMode.IgnoreSchema && mode != XmlReadMode.InferSchema)
5359 {
5361 }
5362 else
5363 {
5364 reader.Skip();
5365 }
5367 return result;
5368 }
5369 if (reader.LocalName == "schema" && reader.NamespaceURI.StartsWith("http://www.w3.org/", StringComparison.Ordinal))
5370 {
5371 if (DataSet != null)
5372 {
5374 }
5375 else
5376 {
5378 }
5379 throw ExceptionBuilder.DataSetUnsupportedSchema("http://www.w3.org/2001/XMLSchema");
5380 }
5381 xmlElement = xmlDocument.CreateElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);
5382 if (reader.HasAttributes)
5383 {
5384 int attributeCount = reader.AttributeCount;
5385 for (int i = 0; i < attributeCount; i++)
5386 {
5387 reader.MoveToAttribute(i);
5388 if (reader.NamespaceURI.Equals("http://www.w3.org/2000/xmlns/"))
5389 {
5390 xmlElement.SetAttribute(reader.Name, reader.GetAttribute(i));
5391 continue;
5392 }
5393 XmlAttribute xmlAttribute = xmlElement.SetAttributeNode(reader.LocalName, reader.NamespaceURI);
5394 xmlAttribute.Prefix = reader.Prefix;
5395 xmlAttribute.Value = reader.GetAttribute(i);
5396 }
5397 }
5398 reader.Read();
5399 }
5400 while (MoveToElement(reader, depth))
5401 {
5402 if (reader.LocalName == "Schema" && reader.NamespaceURI == "urn:schemas-microsoft-com:xml-data")
5403 {
5404 if (!flag && !flag2 && mode != XmlReadMode.IgnoreSchema && mode != XmlReadMode.InferSchema)
5405 {
5406 ReadXDRSchema(reader);
5407 flag = true;
5408 isXdr = true;
5409 }
5410 else
5411 {
5412 reader.Skip();
5413 }
5414 continue;
5415 }
5416 if (reader.LocalName == "schema" && reader.NamespaceURI == "http://www.w3.org/2001/XMLSchema")
5417 {
5418 if (mode != XmlReadMode.IgnoreSchema && mode != XmlReadMode.InferSchema)
5419 {
5421 flag = true;
5422 }
5423 else
5424 {
5425 reader.Skip();
5426 }
5427 continue;
5428 }
5429 if (reader.LocalName == "diffgram" && reader.NamespaceURI == "urn:schemas-microsoft-com:xml-diffgram-v1")
5430 {
5431 if (mode == XmlReadMode.DiffGram || mode == XmlReadMode.IgnoreSchema)
5432 {
5433 if (Columns.Count == 0)
5434 {
5435 if (reader.IsEmptyElement)
5436 {
5437 reader.Read();
5438 return XmlReadMode.DiffGram;
5439 }
5440 throw ExceptionBuilder.DataTableInferenceNotSupported();
5441 }
5442 ReadXmlDiffgram(reader);
5443 result = XmlReadMode.DiffGram;
5444 }
5445 else
5446 {
5447 reader.Skip();
5448 }
5449 continue;
5450 }
5451 if (reader.LocalName == "schema" && reader.NamespaceURI.StartsWith("http://www.w3.org/", StringComparison.Ordinal))
5452 {
5453 if (DataSet != null)
5454 {
5456 }
5457 else
5458 {
5460 }
5461 throw ExceptionBuilder.DataSetUnsupportedSchema("http://www.w3.org/2001/XMLSchema");
5462 }
5463 if (mode == XmlReadMode.DiffGram)
5464 {
5465 reader.Skip();
5466 continue;
5467 }
5468 flag2 = true;
5469 if (mode == XmlReadMode.InferSchema)
5470 {
5471 XmlNode newChild = xmlDocument.ReadNode(reader);
5472 xmlElement.AppendChild(newChild);
5473 continue;
5474 }
5475 if (Columns.Count == 0)
5476 {
5477 throw ExceptionBuilder.DataTableInferenceNotSupported();
5478 }
5479 if (xmlDataLoader == null)
5480 {
5481 xmlDataLoader = new XmlDataLoader(this, isXdr, xmlElement, mode == XmlReadMode.IgnoreSchema);
5482 }
5483 xmlDataLoader.LoadData(reader);
5484 }
5485 ReadEndElement(reader);
5486 xmlDocument.AppendChild(xmlElement);
5487 if (xmlDataLoader == null)
5488 {
5489 xmlDataLoader = new XmlDataLoader(this, isXdr, mode == XmlReadMode.IgnoreSchema);
5490 }
5491 switch (mode)
5492 {
5493 case XmlReadMode.DiffGram:
5495 return result;
5496 case XmlReadMode.InferSchema:
5497 if (Columns.Count == 0)
5498 {
5499 throw ExceptionBuilder.DataTableInferenceNotSupported();
5500 }
5501 break;
5502 }
5503 }
5505 return result;
5506 }
5507 finally
5508 {
5509 disposable?.Dispose();
5510 }
5511 }
void RestoreEnforceConstraints(bool value)
Definition DataSet.cs:783
bool IsEmptyXml(XmlReader reader)
void ReadXmlSchema(Stream? stream)
void ReadXmlDiffgram(XmlReader reader)
DataColumnCollection Columns
Definition DataTable.cs:327
void RestoreConstraint(bool originalEnforceConstraint)
void ReadEndElement(XmlReader reader)
void ReadXDRSchema(XmlReader reader)
bool MoveToElement(XmlReader reader, int depth)
string? GetAttribute(string name)
virtual void Skip()
Definition XmlReader.cs:532
bool MoveToAttribute(string name)
virtual bool HasAttributes
Definition XmlReader.cs:124
virtual XmlNodeType MoveToContent()
Definition XmlReader.cs:604
XmlNodeType NodeType
Definition XmlReader.cs:62
virtual string Name
Definition XmlReader.cs:65

References System.Data.DataTable._enforceConstraints, System.Xml.XmlReader.AttributeCount, System.Data.DataTable.Columns, System.Data.InternalDataCollectionBase.Count, System.Data.ExceptionBuilder.DataSetUnsupportedSchema(), System.Data.ExceptionBuilder.DataTableInferenceNotSupported(), System.Xml.XmlReader.Depth, System.Runtime.Serialization.Dictionary, System.Data.DataSet.EnforceConstraints, System.Data.DataTable.EnforceConstraints, System.Data.TypeLimiter.EnterRestrictedScope(), System.Xml.XmlReader.GetAttribute(), System.Xml.XmlReader.HasAttributes, System.Xml.XmlReader.IsEmptyElement, System.Data.DataTable.IsEmptyXml(), System.Xml.XmlReader.LocalName, System.Xml.XmlReader.MoveToAttribute(), System.Xml.XmlReader.MoveToContent(), System.Data.DataTable.MoveToElement(), System.Xml.XmlReader.Name, System.Xml.XmlReader.NamespaceURI, System.Xml.XmlReader.NodeType, System.Xml.XmlReader.Prefix, System.Xml.XmlReader.Read(), System.Data.DataTable.ReadEndElement(), System.Data.DataTable.ReadXDRSchema(), System.Data.DataTable.ReadXmlDiffgram(), System.Data.DataTable.ReadXmlSchema(), System.Data.DataTable.RestoreConstraint(), System.Data.DataSet.RestoreEnforceConstraints(), and System.Xml.XmlReader.Skip().