예제 #1
0
        private void GenerateInstanceAttribute(XmlSchemaAttribute attr, InstanceElement elem)
        {
            if (attr.Use == XmlSchemaUse.Prohibited || attr.AttributeSchemaType == null)
            {
                return;
            }
            InstanceAttribute iAttr = new InstanceAttribute(attr.QualifiedName)
            {
                DefaultValue   = attr.DefaultValue,
                FixedValue     = attr.FixedValue,
                AttrUse        = attr.Use,
                ValueGenerator = XmlValueGenerator.TryCreateGenerator(attr.AttributeSchemaType.Datatype, listLength)
            };

            if (iAttr.ValueGenerator != null && iAttr.ValueGenerator.Prefix == null)
            {
                iAttr.ValueGenerator.Prefix = iAttr.QualifiedName.Name;
            }
            elem.AddAttribute(iAttr);
        }
예제 #2
0
 private void ProcessComplexType(XmlSchemaComplexType ct, InstanceElement elem)
 {
     if (ct.ContentModel != null && ct.ContentModel is XmlSchemaSimpleContent)
     {
         elem.ValueGenerator = XmlValueGenerator.TryCreateGenerator(ct.Datatype, listLength);
     }
     else
     {
         GenerateParticle(ct.ContentTypeParticle, false, elem);
     }
     //Check for attribute wild card
     if (ct.AttributeWildcard != null)
     {
         GenerateAttributeWildCard(ct, elem);
     }
     //Check for attributes if simple/complex content
     if (ct.AttributeUses.Count > 0)
     {
         GenerateAttribute(ct.AttributeUses, elem);
     }
 }
예제 #3
0
        private bool GenerateElement(XmlSchemaElement e, bool root, InstanceGroup parentElem, XmlSchemaAny any)
        {
            XmlSchemaElement eGlobalDecl = e;

            if (!e.RefName.IsEmpty)
            {
                eGlobalDecl = (XmlSchemaElement)schemaSet.GlobalElements[e.QualifiedName];
            }
            if (!eGlobalDecl.IsAbstract)
            {
                InstanceElement elem = (InstanceElement)elementTypesProcessed[eGlobalDecl];
                if (elem != null)
                {
                    Debug.Assert(!root);
                    if (any == null && e.MinOccurs > 0)
                    { //If not generating for any or optional ref to cyclic global element
                        decimal occurs = e.MaxOccurs;
                        if (e.MaxOccurs >= maxThreshold)
                        {
                            occurs = maxThreshold;
                        }
                        if (e.MinOccurs > occurs)
                        {
                            occurs = e.MinOccurs;
                        }
                        parentElem.AddChild(elem.Clone(occurs));
                    }
                    return(false);
                }
                elem = new InstanceElement(eGlobalDecl.QualifiedName);

                if (root)
                {
                    instanceRoot = elem;
                }
                else
                {
                    parentElem.AddChild(elem);
                }

                //Get minOccurs, maxOccurs alone from the current particle, everything else pick up from globalDecl
                if (any != null)
                { //Element from any
                    elem.Occurs = any.MaxOccurs >= maxThreshold ? maxThreshold : any.MaxOccurs;
                    elem.Occurs = any.MinOccurs > elem.Occurs ? any.MinOccurs : elem.Occurs;
                }
                else
                {
                    elem.Occurs = e.MaxOccurs >= maxThreshold ? maxThreshold : e.MaxOccurs;
                    elem.Occurs = e.MinOccurs > elem.Occurs ? e.MinOccurs : elem.Occurs;
                }
                elem.DefaultValue = eGlobalDecl.DefaultValue;
                elem.FixedValue   = eGlobalDecl.FixedValue;
                elem.IsNillable   = eGlobalDecl.IsNillable;

                if (eGlobalDecl.ElementSchemaType == AnyType)
                {
                    elem.ValueGenerator = XmlValueGenerator.AnyGenerator;
                }
                else
                {
                    if (eGlobalDecl.ElementSchemaType is XmlSchemaComplexType ct)
                    {
                        elementTypesProcessed.Add(eGlobalDecl, elem);
                        if (!ct.IsAbstract)
                        {
                            elem.IsMixed = ct.IsMixed;
                            ProcessComplexType(ct, elem);
                        }
                        else
                        { // Ct is abstract, need to generate instance elements with xsi:type
                            XmlSchemaComplexType dt = GetDerivedType(ct);
                            if (dt != null)
                            {
                                elem.XsiType = dt.QualifiedName;
                                ProcessComplexType(dt, elem);
                            }
                        }
                    }
                    else
                    { //elementType is XmlSchemaSimpleType
                        elem.ValueGenerator = XmlValueGenerator.TryCreateGenerator(eGlobalDecl.ElementSchemaType.Datatype, listLength);
                    }
                }
                if (elem.ValueGenerator != null && elem.ValueGenerator.Prefix == null)
                {
                    elem.ValueGenerator.Prefix = elem.QualifiedName.Name;
                }
                return(true);
            } // End of e.IsAbstract
            return(false);
        }