internal XmlSchemaSet InferSchema1(XmlReader instanceDocument, XmlSchemaSet schemas)
{
if (instanceDocument == null)
{
throw new ArgumentNullException("instanceDocument");
}
this.rootSchema = null;
xtr = instanceDocument;
schemas.Compile();
this.schemaSet = schemas;
//schemas = new Hashtable();
//while(xtr.Read())
while (xtr.NodeType != XmlNodeType.Element && xtr.Read()) ;
if (xtr.NodeType == XmlNodeType.Element)
{
//Create and process the root element
TargetNamespace = xtr.NamespaceURI;
if ( xtr.NamespaceURI == XmlSchema.Namespace)
{
throw new XmlSchemaInferenceException(Res.SchInf_schema, 0, 0);
}
XmlSchemaElement xse = null;
foreach (XmlSchemaElement elem in schemas.GlobalElements.Values)
{
if (elem.Name == xtr.LocalName && elem.QualifiedName.Namespace == xtr.NamespaceURI)
{
rootSchema = elem.Parent as XmlSchema;
xse = elem;
break;
}
}
if (rootSchema == null)
{
//rootSchema = CreateXmlSchema(xtr.NamespaceURI);
xse = AddElement(xtr.LocalName, xtr.Prefix, xtr.NamespaceURI, null, null, -1);
}
else
{
//bRefine = true;
InferElement(xse, false, rootSchema);
}
/* foreach (ReplaceList listItem in schemaList)
{
if (listItem.position < listItem.col.Count)
{
XmlSchemaElement particle = listItem.col[listItem.position] as XmlSchemaElement;
if (particle != null && (particle.RefName.Namespace == XmlSchema.Namespace))
{
XmlSchemaAny any = new XmlSchemaAny();
if (particle.MaxOccurs != 1)
{
any.MaxOccurs = particle.MaxOccurs;
}
if (particle.MinOccurs != 1)
{
any.MinOccurs = particle.MinOccurs;
}
any.ProcessContents = XmlSchemaContentProcessing.Skip;
any.MinOccurs = decimal.Zero;
any.Namespace = particle.RefName.Namespace;
listItem.col[listItem.position] = any;
}
}
}*/
foreach(String prefix in this.NamespaceManager)
{
if (!prefix.Equals("xml") && !prefix.Equals("xmlns"))
{
String ns = this.NamespaceManager.LookupNamespace(this.nametable.Get(prefix));
if (ns.Length != 0) { //Do not add xmlns=""
rootSchema.Namespaces.Add(prefix, ns);
}
}
}
Debug.Assert(this.rootSchema != null, "rootSchema is null");
schemas.Reprocess(rootSchema);
schemas.Compile();
//break;
}
else
{
throw new XmlSchemaInferenceException(Res.SchInf_NoElement, 0, 0);
}
return schemas;
}