System.Xml.Schema.XmlSchemaInference.ProcessAttributes C# (CSharp) Méthode

ProcessAttributes() private méthode

private ProcessAttributes ( XmlSchemaElement &xse, XmlSchemaType effectiveSchemaType, bool bCreatingNewType, XmlSchema parentSchema ) : void
xse XmlSchemaElement
effectiveSchemaType XmlSchemaType
bCreatingNewType bool
parentSchema XmlSchema
Résultat void
            internal void ProcessAttributes(ref XmlSchemaElement xse, XmlSchemaType effectiveSchemaType, bool bCreatingNewType, XmlSchema parentSchema)
            {
                XmlSchemaObjectCollection attributesSeen = new XmlSchemaObjectCollection();
                XmlSchemaComplexType ct = effectiveSchemaType as XmlSchemaComplexType;
                
                Debug.Assert(xtr.NodeType == XmlNodeType.Attribute);
                do
                {
                    if (xtr.NamespaceURI == XmlSchema.Namespace)
                    {
                        throw new XmlSchemaInferenceException(Res.SchInf_schema, 0, 0);
                    }

                    if (xtr.NamespaceURI == "http://www.w3.org/2000/xmlns/")
                    {
                        if (xtr.Prefix=="xmlns") 
                            NamespaceManager.AddNamespace(xtr.LocalName, xtr.Value);
                    }
                    else if (xtr.NamespaceURI == "http://www.w3.org/2001/XMLSchema-instance")
                    {
                        string localName = xtr.LocalName;
                        if (localName == "nil") 
                        {
                            xse.IsNillable = true;
                        }
                        else if (localName != "type" && localName != "schemaLocation" && localName != "noNamespaceSchemaLocation")
                        {
                            throw new XmlSchemaInferenceException(Res.Sch_NotXsiAttribute,localName);
                        }
                    }
                    else
                    {
                        if (ct == null || ct == XmlSchemaComplexType.AnyType)
                        {
                            ct = new XmlSchemaComplexType();
                            xse.SchemaType = ct;
                        }

                        XmlSchemaAttribute xsa=null;
                        //The earlier assumption of checking just schemaTypeName !Empty is not correct for schemas that are not generated by us, schemaTypeName can point to any complex type as well
                        //Check that it is a simple type by checking typeCode
                        //Switch to complex type simple content extension
                        if (effectiveSchemaType != null && effectiveSchemaType.Datatype != null && !xse.SchemaTypeName.IsEmpty)  
                        {
                            //type was previously simple type, now it will become complex with simple type extension
                            Debug.Assert(ct != null);
                            XmlSchemaSimpleContent sc = new XmlSchemaSimpleContent();
                            ct.ContentModel = sc;
                            XmlSchemaSimpleContentExtension sce = new XmlSchemaSimpleContentExtension();
                            sc.Content = sce;
                            sce.BaseTypeName = xse.SchemaTypeName;
                            sce.LineNumber = xse.LineNumber;
                            xse.LineNumber = 0;
                            xse.SchemaTypeName = XmlQualifiedName.Empty; //re-set the name
                        }
                        
                        Debug.Assert(ct != null); //either the user-defined type itself is a complex type or we switched from a simple type to a complex type
                        if (ct.ContentModel != null) 
                        {
                            XmlSchemaSimpleContentExtension sce = CheckSimpleContentExtension(ct);
                            Debug.Assert(sce != null);
                            xsa = AddAttribute(xtr.LocalName, xtr.Prefix, xtr.NamespaceURI, xtr.Value, bCreatingNewType, parentSchema, sce.Attributes, ct.AttributeUses);
                        } 
                        else //add atributes directly to complex type
                        {
                            xsa = AddAttribute(xtr.LocalName, xtr.Prefix, xtr.NamespaceURI, xtr.Value, bCreatingNewType, parentSchema, ct.Attributes, ct.AttributeUses);
                        }
                        if (xsa != null) {
                            attributesSeen.Add(xsa);
                        }
                    }
                    
                } while (xtr.MoveToNextAttribute());
                if (!bCreatingNewType)
                {   
                    //make attributes that did not appear this time optional
                    if (ct!=null) {
                        MakeExistingAttributesOptional(ct, attributesSeen);
                    }
                }
            }