internal void ReadXmlSchema(XmlReader reader, bool denyResolving)
{
long logScopeId = DataCommonEventSource.Log.EnterScope("<ds.DataSet.ReadXmlSchema|INFO> {0}, reader, denyResolving={1}", ObjectID, denyResolving);
try
{
int iCurrentDepth = -1;
if (reader == null)
{
return;
}
if (reader is XmlTextReader)
{
((XmlTextReader)reader).WhitespaceHandling = WhitespaceHandling.None;
}
XmlDocument xdoc = new XmlDocument(); // we may need this to infer the schema
if (reader.NodeType == XmlNodeType.Element)
{
iCurrentDepth = reader.Depth;
}
reader.MoveToContent();
if (reader.NodeType == XmlNodeType.Element)
{
// if reader points to the schema load it...
if (reader.LocalName == Keywords.XDR_SCHEMA && reader.NamespaceURI == Keywords.XDRNS)
{
// load XDR schema and exit
ReadXDRSchema(reader);
return;
}
if (reader.LocalName == Keywords.XSD_SCHEMA && reader.NamespaceURI == Keywords.XSDNS)
{
// load XSD schema and exit
ReadXSDSchema(reader, denyResolving);
return;
}
if (reader.LocalName == Keywords.XSD_SCHEMA && reader.NamespaceURI.StartsWith(Keywords.XSD_NS_START, StringComparison.Ordinal))
{
throw ExceptionBuilder.DataSetUnsupportedSchema(Keywords.XSDNS);
}
// ... otherwise backup the top node and all its attributes
XmlElement topNode = xdoc.CreateElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);
if (reader.HasAttributes)
{
int attrCount = reader.AttributeCount;
for (int i = 0; i < attrCount; i++)
{
reader.MoveToAttribute(i);
if (reader.NamespaceURI.Equals(Keywords.XSD_XMLNS_NS))
{
topNode.SetAttribute(reader.Name, reader.GetAttribute(i));
}
else
{
XmlAttribute attr = topNode.SetAttributeNode(reader.LocalName, reader.NamespaceURI);
attr.Prefix = reader.Prefix;
attr.Value = reader.GetAttribute(i);
}
}
}
reader.Read();
while (MoveToElement(reader, iCurrentDepth))
{
// if reader points to the schema load it...
if (reader.LocalName == Keywords.XDR_SCHEMA && reader.NamespaceURI == Keywords.XDRNS)
{
// load XDR schema and exit
ReadXDRSchema(reader);
return;
}
if (reader.LocalName == Keywords.XSD_SCHEMA && reader.NamespaceURI == Keywords.XSDNS)
{
// load XSD schema and exit
ReadXSDSchema(reader, denyResolving);
return;
}
if (reader.LocalName == Keywords.XSD_SCHEMA && reader.NamespaceURI.StartsWith(Keywords.XSD_NS_START, StringComparison.Ordinal))
{
throw ExceptionBuilder.DataSetUnsupportedSchema(Keywords.XSDNS);
}
XmlNode node = xdoc.ReadNode(reader);
topNode.AppendChild(node);
}
// read the closing tag of the current element
ReadEndElement(reader);
// if we are here no schema has been found
xdoc.AppendChild(topNode);
// so we InferSchema
InferSchema(xdoc, null, XmlReadMode.Auto);
}
}
finally
{
DataCommonEventSource.Log.ExitScope(logScopeId);
}
}