Пример #1
0
        private static XmlValueGenerator CreateListGenerator(XmlSchemaDatatype dtype, CompiledFacets facets, int listLength)
        {
            XmlSchemaDatatype itemType  = (XmlSchemaDatatype)dtype.GetType().InvokeMember("itemType", BindingFlags.GetField | BindingFlags.NonPublic | BindingFlags.Instance, null, dtype, null);
            Generator_List    list_genr = new Generator_List(facets);

            list_genr.ListLength = listLength;
            list_genr.AddGenerator(XmlValueGenerator.CreateGenerator(itemType, listLength));
            return(list_genr);
        }
Пример #2
0
        private static XmlValueGenerator CreateUnionGenerator(XmlSchemaDatatype dtype, CompiledFacets facets, int listLength)
        {
            XmlSchemaSimpleType[] memberTypes = (XmlSchemaSimpleType[])dtype.GetType().InvokeMember("types", BindingFlags.GetField | BindingFlags.NonPublic | BindingFlags.Instance, null, dtype, null);
            Generator_Union       union_genr  = new Generator_Union(facets);

            foreach (XmlSchemaSimpleType st1 in memberTypes)
            {
                union_genr.AddGenerator(XmlValueGenerator.CreateGenerator(st1.Datatype, listLength));
            }

            return(union_genr);
        }
Пример #3
0
        private void GenerateInstanceAttribute(XmlSchemaAttribute attr, InstanceElement elem)
        {
            if (attr.Use == XmlSchemaUse.Prohibited || attr.AttributeSchemaType == null)
            {
                return;
            }
            InstanceAttribute iAttr = new InstanceAttribute(attr.QualifiedName);

            iAttr.DefaultValue   = attr.DefaultValue;
            iAttr.FixedValue     = attr.FixedValue;
            iAttr.AttrUse        = attr.Use;
            iAttr.ValueGenerator = XmlValueGenerator.CreateGenerator(attr.AttributeSchemaType.Datatype, _listLength);

            if (iAttr.ValueGenerator != null && iAttr.ValueGenerator.Prefix == null)
            {
                iAttr.ValueGenerator.Prefix = iAttr.QualifiedName.Name;
            }

            elem.AddAttribute(iAttr);
        }
Пример #4
0
 private void ProcessComplexType(XmlSchemaComplexType ct, InstanceElement elem)
 {
     if (ct.ContentModel != null && ct.ContentModel is XmlSchemaSimpleContent)
     {
         elem.ValueGenerator = XmlValueGenerator.CreateGenerator(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);
     }
 }
Пример #5
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
                {
                    XmlSchemaComplexType ct = eGlobalDecl.ElementSchemaType as XmlSchemaComplexType;
                    if (ct != null)
                    {
                        _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.CreateGenerator(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);
        }