Inheritance: XmlSchemaGroupBase
Example #1
0
        public static System.Xml.Schema.XmlSchemaComplexType GetTypedTableSchema(System.Xml.Schema.XmlSchemaSet xs)
        {
            System.Xml.Schema.XmlSchemaComplexType type     = new System.Xml.Schema.XmlSchemaComplexType();
            System.Xml.Schema.XmlSchemaSequence    sequence = new System.Xml.Schema.XmlSchemaSequence();
            Products ds = new Products();

            xs.Add(ds.GetSchemaSerializable());
            System.Xml.Schema.XmlSchemaAny any1 = new System.Xml.Schema.XmlSchemaAny();
            any1.Namespace       = "http://www.w3.org/2001/XMLSchema";
            any1.MinOccurs       = new decimal(0);
            any1.MaxOccurs       = decimal.MaxValue;
            any1.ProcessContents = System.Xml.Schema.XmlSchemaContentProcessing.Lax;
            sequence.Items.Add(any1);
            System.Xml.Schema.XmlSchemaAny any2 = new System.Xml.Schema.XmlSchemaAny();
            any2.Namespace       = "urn:schemas-microsoft-com:xml-diffgram-v1";
            any2.MinOccurs       = new decimal(1);
            any2.ProcessContents = System.Xml.Schema.XmlSchemaContentProcessing.Lax;
            sequence.Items.Add(any2);
            System.Xml.Schema.XmlSchemaAttribute attribute1 = new System.Xml.Schema.XmlSchemaAttribute();
            attribute1.Name       = "namespace";
            attribute1.FixedValue = ds.Namespace;
            type.Attributes.Add(attribute1);
            System.Xml.Schema.XmlSchemaAttribute attribute2 = new System.Xml.Schema.XmlSchemaAttribute();
            attribute2.Name       = "tableTypeName";
            attribute2.FixedValue = "ProductDataTable";
            type.Attributes.Add(attribute2);
            type.Particle = sequence;
            return(type);
        }
        public static System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(System.Xml.Schema.XmlSchemaSet xs)
        {
            TypedDataSet ds = new TypedDataSet();

            System.Xml.Schema.XmlSchemaComplexType type     = new System.Xml.Schema.XmlSchemaComplexType();
            System.Xml.Schema.XmlSchemaSequence    sequence = new System.Xml.Schema.XmlSchemaSequence();
            xs.Add(ds.GetSchemaSerializable());
            if (PublishLegacyWSDL())
            {
                System.Xml.Schema.XmlSchemaAny any = new System.Xml.Schema.XmlSchemaAny();
                any.Namespace = ds.Namespace;
                sequence.Items.Add(any);
            }
            else
            {
                System.Xml.Schema.XmlSchemaAny any1 = new System.Xml.Schema.XmlSchemaAny();
                any1.Namespace       = "http://www.w3.org/2001/XMLSchema";
                any1.MinOccurs       = new System.Decimal(0);
                any1.ProcessContents = System.Xml.Schema.XmlSchemaContentProcessing.Lax;
                sequence.Items.Add(any1);
                System.Xml.Schema.XmlSchemaAny any2 = new System.Xml.Schema.XmlSchemaAny();
                any2.Namespace       = "urn:schemas-microsoft-com:xml-diffgram-v1";
                any2.MinOccurs       = new System.Decimal(0);
                any2.ProcessContents = System.Xml.Schema.XmlSchemaContentProcessing.Lax;
                sequence.Items.Add(any2);
                sequence.MaxOccurs = System.Decimal.MaxValue;
                System.Xml.Schema.XmlSchemaAttribute attribute = new System.Xml.Schema.XmlSchemaAttribute();
                attribute.Name       = "namespace";
                attribute.FixedValue = ds.Namespace;
                type.Attributes.Add(attribute);
            }
            type.Particle = sequence;
            return(type);
        }
		public static XmlSchemaElement AndSchema()
		{
			var type = new XmlSchemaComplexType();

			var any = new XmlSchemaAny();
			any.MinOccurs = 1;
			any.MaxOccursString = "unbounded";
			any.ProcessContents = XmlSchemaContentProcessing.Strict;
			any.Namespace = "##local";

			var sequence = new XmlSchemaSequence();
			type.Particle = sequence;
			sequence.Items.Add(any);

			var attrib = new XmlSchemaAttribute();
			attrib.Name = "expressionLanguage";
			attrib.Use = XmlSchemaUse.Optional;
			attrib.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
			type.Attributes.Add(attrib);

			attrib = new XmlSchemaAttribute();
			attrib.Name = "failMessage";
			attrib.Use = XmlSchemaUse.Optional;
			attrib.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
			type.Attributes.Add(attrib);

			var element = new XmlSchemaElement();
			element.Name = "and";
			element.SchemaType = type;

			return element;
		}
Example #4
0
        private void CreateSchema(String name, DataTable dt)
        {
            XmlSchema schema = new XmlSchema();
            rootElem = new XmlSchemaElement();
            rootElem.Name = XmlConvert.EncodeName(name);
            schema.Items.Add(rootElem);

            XmlSchemaComplexType rootContent = new XmlSchemaComplexType();
            rootElem.SchemaType = rootContent;

            XmlSchemaSequence s1 = new XmlSchemaSequence();
            rootContent.Particle = s1;

            rowElem = new XmlSchemaElement();
            rowElem.Name = "row";
            rowElem.MinOccurs = 0;
            rowElem.MaxOccursString = "unbounded";
            s1.Items.Add(rowElem);

            XmlSchemaComplexType rowContent = new XmlSchemaComplexType();
            rowElem.SchemaType = rowContent;
            XmlSchemaSequence s2 = new XmlSchemaSequence();
            rowContent.Particle = s2;

            DataRow[] dt_rows = dt.Select();
            dataElem = new XmlSchemaElement[dt_rows.Length];
            dataContent = new XmlSchemaSimpleType[dt_rows.Length];
            for (int k = 0; k < dt_rows.Length; k++)
            {
                DataRow r = dt_rows[k];
                dataElem[k] = new XmlSchemaElement();
                dataElem[k].Name = XmlConvert.EncodeName((String)r["ColumnName"]);
                if (r["AllowDBNull"] != DBNull.Value && (bool)r["AllowDBNull"])
                    dataElem[k].MinOccurs = 0;
                Type dataType = (Type)r["DataType"];
                XmlTypeCode typeCode = XQuerySequenceType.GetXmlTypeCode(dataType);
                if (typeCode == XmlTypeCode.Item)
                    dataContent[k] = null;
                else
                {
                    dataContent[k] = XmlSchemaType.GetBuiltInSimpleType(typeCode);
                    dataElem[k].SchemaTypeName = dataContent[k].QualifiedName;
                }
                s2.Items.Add(dataElem[k]);
            }

            m_schemaSet = new XmlSchemaSet();
            m_schemaSet.Add(schema);
            m_schemaSet.Compile();

            NewNode(XmlNodeType.XmlDeclaration, null, null, null);
            NewNode(XmlNodeType.Element, name, null, null);

            m_readState = ReadState.Initial;

            //XmlWriter writer = XmlWriter.Create("c:\\work\\schema.xml");
            //schema.Write(writer);
            //writer.Close();
        }
Example #5
0
        private string genExpXsd()
        {
            sch.XmlSchema expSchema = new sch.XmlSchema();

            //Create the PdeData element
            sch.XmlSchemaElement rootElement = new sch.XmlSchemaElement();
            rootElement.Name = ROOT_ELEMENT;
            expSchema.Items.Add(rootElement);
            sch.XmlSchemaComplexType rootType = new sch.XmlSchemaComplexType();
            rootType.IsMixed = false;
            sch.XmlSchemaSequence rootSequence = new sch.XmlSchemaSequence();
            rootType.Particle      = rootSequence;
            rootElement.SchemaType = rootType;

            foreach (ExportItemMap itemMap in exportItems)
            {
                if (itemMap.mapType == ProntoDoc.Framework.CoreObject.MapType.singleCell)
                {
                    sch.XmlSchemaElement item = new sch.XmlSchemaElement();
                    item.Name           = itemMap.treeNodeName;
                    item.SchemaTypeName = new XmlQualifiedName(itemMap.dataType, ns);
                    rootSequence.Items.Add(item);
                }
                else
                {
                    sch.XmlSchemaElement tabElement = new sch.XmlSchemaElement();
                    tabElement.MinOccurs       = 0;
                    tabElement.MaxOccursString = "unbounded";
                    tabElement.Name            = itemMap.treeNodeName;
                    rootSequence.Items.Add(tabElement);

                    sch.XmlSchemaComplexType tabType = new sch.XmlSchemaComplexType();
                    tabType.IsMixed = false;
                    sch.XmlSchemaAll tabAll = new sch.XmlSchemaAll();
                    tabType.Particle      = tabAll;
                    tabElement.SchemaType = tabType;

                    //generate children node
                    foreach (TableColumnMap col in itemMap.tabCols)
                    {
                        sch.XmlSchemaElement item = new sch.XmlSchemaElement();
                        item.Name           = col.treeNodeName;
                        item.SchemaTypeName = new XmlQualifiedName(col.dataType, ns);
                        tabAll.Items.Add(item);
                    }
                }
            }

            expSchema.Compile(new sch.ValidationEventHandler(ValidationEventHandler));
            FileStream stream = new FileStream("e:\\tempout.xsd", FileMode.Create);

            //Write the file
            expSchema.Write(stream);
            stream.Close();

            return("e:\\tempout.xsd");
        }
Example #6
0
        /// <summary>
        /// Формируем XmlSchema для правильного отображения индикаторов группы в VGridControl
        /// </summary>
        /// <param name="elmList">названия всех по</param>
        /// <returns>Возвращаем поток в который записана XmlSchema</returns>
        public static MemoryStream CreateXmlSchemaForIndicatorsInGroup(List<string[]> elmList)
        {
            var xmlSchema = new XmlSchema();

            // <xs:element name="root">
            var elementRoot = new XmlSchemaElement();
            xmlSchema.Items.Add(elementRoot);
            elementRoot.Name = "root";
            // <xs:complexType>
            var complexType = new XmlSchemaComplexType();
            elementRoot.SchemaType = complexType;

            // <xs:choice minOccurs="0" maxOccurs="unbounded">
            var choice = new XmlSchemaChoice();
            complexType.Particle = choice;
            choice.MinOccurs = 0;
            choice.MaxOccursString = "unbounded";

            // <xs:element name="record">
            var elementRecord = new XmlSchemaElement();
            choice.Items.Add(elementRecord);
            elementRecord.Name = "record";
            // <xs:complexType>
            var complexType2 = new XmlSchemaComplexType();
            elementRecord.SchemaType = complexType2;

            // <xs:sequence>
            var sequence = new XmlSchemaSequence();
            complexType2.Particle = sequence;

            foreach (var el in elmList)
            {
                var element = new XmlSchemaElement();
                sequence.Items.Add(element);
                element.Name = el[0];
                element.SchemaTypeName = new XmlQualifiedName(el[1], "http://www.w3.org/2001/XMLSchema");
            }

            var schemaSet = new XmlSchemaSet();
            schemaSet.Add(xmlSchema);
            schemaSet.Compile();

            XmlSchema compiledSchema = null;

            foreach (XmlSchema schema1 in schemaSet.Schemas())
                compiledSchema = schema1;

            var nsmgr = new XmlNamespaceManager(new NameTable());
            nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");

            var ms = new MemoryStream();
            if (compiledSchema != null) compiledSchema.Write(ms, nsmgr);
            ms.Position = 0;

            return ms;
        }
Example #7
0
		XmlSchemaComplexType GetStype ()
		{
			XmlSchemaSequence seq = new XmlSchemaSequence ();
			seq.Items.Add (new XmlSchemaAny ());
		
			XmlSchemaComplexType stype = new XmlSchemaComplexType ();
			stype.Particle = seq;
			
			return stype;
		}
Example #8
0
        private Sequence CreateSequence()
        {
            Sequence s = new Sequence();

            if (laxOccurrence)
            {
                s.MinOccurs = 0;
            }
            return(s);
        }
Example #9
0
        private Schema.XmlSchemaSequence CreateSequenceElement(Schema.XmlSchema parent, string name)
        {
            Schema.XmlSchemaElement element = new Schema.XmlSchemaElement();
            element.Name = name;
            parent.Items.Add(element);
            Schema.XmlSchemaComplexType type = new Schema.XmlSchemaComplexType();
            type.IsMixed = false;
            Schema.XmlSchemaSequence sequence = new Schema.XmlSchemaSequence();
            type.Particle      = sequence;
            element.SchemaType = type;

            return(sequence);
        }
Example #10
0
    public static System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(System.Xml.Schema.XmlSchemaSet xs)
    {
        Products ds = new Products();

        System.Xml.Schema.XmlSchemaComplexType type     = new System.Xml.Schema.XmlSchemaComplexType();
        System.Xml.Schema.XmlSchemaSequence    sequence = new System.Xml.Schema.XmlSchemaSequence();
        xs.Add(ds.GetSchemaSerializable());
        System.Xml.Schema.XmlSchemaAny any = new System.Xml.Schema.XmlSchemaAny();
        any.Namespace = ds.Namespace;
        sequence.Items.Add(any);
        type.Particle = sequence;
        return(type);
    }
        internal void ReflectStringParametersMessage() {
            Message inputMessage = InputMessage;
            foreach (ParameterInfo parameterInfo in Method.InParameters) {
                MessagePart part = new MessagePart();
                part.Name = XmlConvert.EncodeLocalName(parameterInfo.Name);
                if (parameterInfo.ParameterType.IsArray) {
                    string typeNs = DefaultNamespace;
                    if (typeNs.EndsWith("/", StringComparison.Ordinal))
                        typeNs += "AbstractTypes";
                    else
                        typeNs += "/AbstractTypes";
                    string typeName = "StringArray";
                    if (!ServiceDescription.Types.Schemas.Contains(typeNs)) {
                        XmlSchema schema = new XmlSchema();
                        schema.TargetNamespace = typeNs;
                        ServiceDescription.Types.Schemas.Add(schema);
                       
                        XmlSchemaElement element = new XmlSchemaElement();
                        element.Name = "String";
                        element.SchemaTypeName = new XmlQualifiedName("string", XmlSchema.Namespace);
                        element.MinOccurs = decimal.Zero;
                        element.MaxOccurs = decimal.MaxValue;
                        XmlSchemaSequence all = new XmlSchemaSequence();
                        all.Items.Add(element);

                        XmlSchemaComplexContentRestriction restriction = new XmlSchemaComplexContentRestriction();
                        restriction.BaseTypeName = new XmlQualifiedName(Soap.ArrayType, Soap.Encoding);
                        restriction.Particle = all;

                        XmlSchemaImport import = new XmlSchemaImport();
                        import.Namespace = restriction.BaseTypeName.Namespace;
                        
                        XmlSchemaComplexContent model = new XmlSchemaComplexContent();
                        model.Content = restriction;

                        XmlSchemaComplexType type = new XmlSchemaComplexType();
                        type.Name = typeName;
                        type.ContentModel = model;

                        schema.Items.Add(type);
                        schema.Includes.Add(import);
                    }
                    part.Type = new XmlQualifiedName(typeName, typeNs);
                }
                else {
                    part.Type = new XmlQualifiedName("string", XmlSchema.Namespace);
                }
                inputMessage.Parts.Add(part);
            }
        }
Example #12
0
        private Sequence PopulateSequence(ComplexType ct)
        {
            Particle p = PopulateParticle(ct);
            Sequence s = p as Sequence;

            if (s != null)
            {
                return(s);
            }
            else
            {
                throw Error(ct, String.Format("Target complexType contains unacceptable type of particle {0}", p));
            }
        }
Example #13
0
        private void InferComplexContent(Element el, string ns,
                                         bool isNew)
        {
            ComplexType ct = ToComplexType(el);

            ToComplexContentType(ct);

            int  position = 0;
            bool consumed = false;

            do
            {
                switch (source.NodeType)
                {
                case XmlNodeType.Element:
                    Sequence s = PopulateSequence(ct);
                    Choice   c = s.Items.Count > 0 ?
                                 s.Items [0] as Choice :
                                 null;
                    if (c != null)
                    {
                        ProcessLax(c, ns);
                    }
                    else
                    {
                        ProcessSequence(ct, s, ns,
                                        ref position,
                                        ref consumed,
                                        isNew);
                    }
                    source.MoveToContent();
                    break;

                case XmlNodeType.Text:
                case XmlNodeType.CDATA:
                case XmlNodeType.SignificantWhitespace:
                    MarkAsMixed(ct);
                    source.ReadString();
                    source.MoveToContent();
                    break;

                case XmlNodeType.EndElement:
                    return;                     // finished

                case XmlNodeType.None:
                    throw new NotImplementedException("Internal Error: Should not happen.");
                }
            } while (true);
        }
Example #14
0
        private Schema.XmlSchemaAll CreateElement(Schema.XmlSchemaSequence parent, string name)
        {
            Schema.XmlSchemaElement element = new Schema.XmlSchemaElement();
            element.MinOccurs       = 0;
            element.MaxOccursString = "unbounded";
            element.Name            = name;
            parent.Items.Add(element);

            Schema.XmlSchemaComplexType type = new Schema.XmlSchemaComplexType();
            type.IsMixed = false;
            Schema.XmlSchemaAll elementAll = new Schema.XmlSchemaAll();
            type.Particle      = elementAll;
            element.SchemaType = type;

            return(elementAll);
        }
Example #15
0
        // Note that it does not return the changed sequence.
        private Choice ToSequenceOfChoice(Sequence s)
        {
            Choice c = new Choice();

            if (laxOccurrence)
            {
                c.MinOccurs = 0;
            }
            c.MaxOccursString = "unbounded";
            foreach (Particle p in s.Items)
            {
                c.Items.Add(p);
            }
            s.Items.Clear();
            s.Items.Add(c);
            return(c);
        }
Example #16
0
        private Parameter[] GetParameters(string messagePartName)
        {
            List <Parameter> parameters = new List <Parameter>();

            //Types types = serviceDescription.Types;
            //System.Xml.Schema.XmlSchema xmlSchema = types.Schemas[0];

            foreach (XmlSchemaElement schemaElement in e.GlobalElements.Values)
            {
                //}
                //foreach (object item in xmlSchema.Items)
                //{
                //    System.Xml.Schema.XmlSchemaElement schemaElement = item as System.Xml.Schema.XmlSchemaElement;
                if (schemaElement != null)
                {
                    if (schemaElement.Name == messagePartName)
                    {
                        System.Xml.Schema.XmlSchemaType        schemaType  = schemaElement.SchemaType;
                        System.Xml.Schema.XmlSchemaComplexType complexType =
                            schemaType as System.Xml.Schema.XmlSchemaComplexType;
                        if (complexType != null)
                        {
                            System.Xml.Schema.XmlSchemaParticle particle = complexType.Particle;
                            System.Xml.Schema.XmlSchemaSequence sequence = particle as System.Xml.Schema.XmlSchemaSequence;
                            if (sequence != null)
                            {
                                foreach (System.Xml.Schema.XmlSchemaElement childElement in sequence.Items)
                                {
                                    string parameterName = childElement.Name;
                                    string parameterType = childElement.SchemaTypeName.Name;
                                    parameters.Add(new Parameter(parameterName, parameterType, null, null));
                                }
                            }
                        }
                        break;
                    }
                }
            }
            return(parameters.ToArray());
        }
 private bool CheckIfCollection(XmlSchemaSequence rootSequence)
 {
     if ((rootSequence.Items == null) || (rootSequence.Items.Count == 0))
     {
         return false;
     }
     this.RemoveOptionalUnknownSerializationElements(rootSequence.Items);
     if (rootSequence.Items.Count != 1)
     {
         return false;
     }
     XmlSchemaObject obj2 = rootSequence.Items[0];
     if (!(obj2 is XmlSchemaElement))
     {
         return false;
     }
     XmlSchemaElement element = (XmlSchemaElement) obj2;
     if (!(element.MaxOccursString == "unbounded"))
     {
         return (element.MaxOccurs > 1M);
     }
     return true;
 }
Example #18
0
        private static XmlSchemaComplexType CreateAnyType(XmlSchemaContentProcessing processContents)
        {
            XmlSchemaComplexType localAnyType = new XmlSchemaComplexType();
            localAnyType.SetQualifiedName(DatatypeImplementation.QnAnyType);

            XmlSchemaAny anyElement = new XmlSchemaAny();
            anyElement.MinOccurs = decimal.Zero;
            anyElement.MaxOccurs = decimal.MaxValue;

            anyElement.ProcessContents = processContents;
            anyElement.BuildNamespaceList(null);
            XmlSchemaSequence seq = new XmlSchemaSequence();
            seq.Items.Add(anyElement);

            localAnyType.SetContentTypeParticle(seq);
            localAnyType.SetContentType(XmlSchemaContentType.Mixed);

            localAnyType.ElementDecl = SchemaElementDecl.CreateAnyTypeElementDecl();
            localAnyType.ElementDecl.SchemaType = localAnyType;

            //Create contentValidator for Any
            ParticleContentValidator contentValidator = new ParticleContentValidator(XmlSchemaContentType.Mixed);
            contentValidator.Start();
            contentValidator.OpenGroup();
            contentValidator.AddNamespaceList(anyElement.NamespaceList, anyElement);
            contentValidator.AddStar();
            contentValidator.CloseGroup();
            ContentValidator anyContentValidator = contentValidator.Finish(true);
            localAnyType.ElementDecl.ContentValidator = anyContentValidator;

            XmlSchemaAnyAttribute anyAttribute = new XmlSchemaAnyAttribute();
            anyAttribute.ProcessContents = processContents;
            anyAttribute.BuildNamespaceList(null);
            localAnyType.SetAttributeWildcard(anyAttribute);
            localAnyType.ElementDecl.AnyAttribute = anyAttribute;
            return localAnyType;
        }
Example #19
0
 private void SetContainer(State state, object container) {
     switch (state) {
         case State.Root:
             break;
         case State.Schema:
             break;
         case State.Annotation:
             this.annotation = (XmlSchemaAnnotation)container;
             break;
         case State.Include:
             this.include = (XmlSchemaInclude)container;
             break;
         case State.Import:
             this.import = (XmlSchemaImport)container;
             break;
         case State.Element:
             this.element = (XmlSchemaElement)container;
             break;
         case State.Attribute:
             this.attribute = (XmlSchemaAttribute)container;
             break;
         case State.AttributeGroup:
             this.attributeGroup = (XmlSchemaAttributeGroup)container;
             break;
         case State.AttributeGroupRef:
             this.attributeGroupRef = (XmlSchemaAttributeGroupRef)container;
             break;
         case State.AnyAttribute:
             this.anyAttribute = (XmlSchemaAnyAttribute)container;
             break;
         case State.Group:
             this.group = (XmlSchemaGroup)container;
             break;
         case State.GroupRef:
             this.groupRef = (XmlSchemaGroupRef)container;
             break;
         case State.All:
             this.all = (XmlSchemaAll)container;
             break;
         case State.Choice:
             this.choice = (XmlSchemaChoice)container;
             break;
         case State.Sequence:
             this.sequence = (XmlSchemaSequence)container;
             break;
         case State.Any:
             this.anyElement = (XmlSchemaAny)container;
             break;
         case State.Notation:
             this.notation = (XmlSchemaNotation)container;
             break;
         case State.SimpleType:
             this.simpleType = (XmlSchemaSimpleType)container;
             break;
         case State.ComplexType:
             this.complexType = (XmlSchemaComplexType)container;
             break;
         case State.ComplexContent:
             this.complexContent = (XmlSchemaComplexContent)container;
             break;
         case State.ComplexContentExtension:
             this.complexContentExtension = (XmlSchemaComplexContentExtension)container;
             break;
         case State.ComplexContentRestriction:
             this.complexContentRestriction = (XmlSchemaComplexContentRestriction)container;
             break;
         case State.SimpleContent:
             this.simpleContent = (XmlSchemaSimpleContent)container;
             break;
         case State.SimpleContentExtension:
             this.simpleContentExtension = (XmlSchemaSimpleContentExtension)container;
             break;
         case State.SimpleContentRestriction:
             this.simpleContentRestriction = (XmlSchemaSimpleContentRestriction)container;
             break;
         case State.SimpleTypeUnion:
             this.simpleTypeUnion = (XmlSchemaSimpleTypeUnion)container;
             break;
         case State.SimpleTypeList:
             this.simpleTypeList = (XmlSchemaSimpleTypeList)container;
             break;
         case State.SimpleTypeRestriction:
             this.simpleTypeRestriction = (XmlSchemaSimpleTypeRestriction)container;
             break;
         case State.Unique:
         case State.Key:
         case State.KeyRef:
             this.identityConstraint = (XmlSchemaIdentityConstraint)container;
             break;
         case State.Selector:
         case State.Field:
             this.xpath = (XmlSchemaXPath)container;
             break;
         case State.MinExclusive:
         case State.MinInclusive:
         case State.MaxExclusive:
         case State.MaxInclusive:
         case State.TotalDigits:
         case State.FractionDigits:
         case State.Length:
         case State.MinLength:
         case State.MaxLength:
         case State.Enumeration:
         case State.Pattern:
         case State.WhiteSpace:
             this.facet = (XmlSchemaFacet)container;
             break;
         case State.AppInfo:
             this.appInfo = (XmlSchemaAppInfo)container;
             break;
         case State.Documentation:
             this.documentation = (XmlSchemaDocumentation)container;
             break;
         case State.Redefine:
             this.redefine = (XmlSchemaRedefine)container;
             break;
         default:
             Debug.Assert(false, "State is " + state);
             break;
     }
 }
Example #20
0
        private void ProcessSequence(ComplexType ct, Sequence s,
                                     string ns, ref int position, ref bool consumed,
                                     bool isNew)
        {
            for (int i = 0; i < position; i++)
            {
                Element iel = s.Items [i] as Element;
                if (ElementMatches(iel, ns))
                {
                    // Sequence element type violation
                    // might happen (might not, but we
                    // cannot backtrack here). So switch
                    // to sequence of choice* here.
                    ProcessLax(ToSequenceOfChoice(s), ns);
                    return;
                }
            }

            if (s.Items.Count <= position)
            {
                QName name = new QName(source.LocalName,
                                       source.NamespaceURI);
                Element nel = CreateElement(name);
                if (laxOccurrence)
                {
                    nel.MinOccurs = 0;
                }
                InferElement(nel, ns, true);
                if (ns == name.Namespace)
                {
                    s.Items.Add(nel);
                }
                else
                {
                    Element re = new Element();
                    if (laxOccurrence)
                    {
                        re.MinOccurs = 0;
                    }
                    re.RefName = name;
                    AddImport(ns, name.Namespace);
                    s.Items.Add(re);
                }
                consumed = true;
                return;
            }
            Element el = s.Items [position] as Element;

            if (el == null)
            {
                throw Error(s, String.Format("Target complex type content sequence has an unacceptable type of particle {0}", s.Items [position]));
            }
            bool matches = ElementMatches(el, ns);

            if (matches)
            {
                if (consumed)
                {
                    el.MaxOccursString = "unbounded";
                }
                InferElement(el, source.NamespaceURI, false);
                source.MoveToContent();
                switch (source.NodeType)
                {
                case XmlNodeType.None:
                    if (source.NodeType ==
                        XmlNodeType.Element)
                    {
                        goto case XmlNodeType.Element;
                    }
                    else if (source.NodeType ==
                             XmlNodeType.EndElement)
                    {
                        goto case XmlNodeType.EndElement;
                    }
                    break;

                case XmlNodeType.Element:
                    ProcessSequence(ct, s, ns, ref position,
                                    ref consumed, isNew);
                    break;

                case XmlNodeType.Text:
                case XmlNodeType.CDATA:
                case XmlNodeType.SignificantWhitespace:
                    MarkAsMixed(ct);
                    source.ReadString();
                    goto case XmlNodeType.None;

                case XmlNodeType.Whitespace:
                    source.ReadString();
                    goto case XmlNodeType.None;

                case XmlNodeType.EndElement:
                    return;

                default:
                    source.Read();
                    break;
                }
            }
            else
            {
                if (consumed)
                {
                    position++;
                    consumed = false;
                    ProcessSequence(ct, s, ns,
                                    ref position, ref consumed,
                                    isNew);
                }
                else
                {
                    ProcessLax(ToSequenceOfChoice(s), ns);
                }
            }
        }
Example #21
0
		public XmlSchema GetSchema ()
		{
			XmlSchema s = new XmlSchema ();
			s.TargetNamespace = "http://www.go-mono.org/schemas";
			s.Id = "monoschema";
			XmlSchemaElement e = new XmlSchemaElement ();
			e.Name = "data";
			s.Items.Add (e);
			XmlSchemaComplexType cs = new XmlSchemaComplexType ();
			XmlSchemaSequence seq = new XmlSchemaSequence ();
			XmlSchemaAny any = new XmlSchemaAny ();
			any.MinOccurs = 0;
			any.MaxOccurs = decimal.MaxValue;
			seq.Items.Add (any);
			cs.Particle = seq;
			e.SchemaType = cs;
			return s;
		}
		QName ExportParameters (MessageBodyDescription msgbody, string name, string ns)
		{
			XmlSchema xs = GetSchema (ns);
			//FIXME: Extract to a HasElement method ?
			foreach (XmlSchemaObject o in xs.Items) {
				XmlSchemaElement e = o as XmlSchemaElement;
				if (e == null)
					continue;

				if (e.Name == name)
					throw new InvalidOperationException (String.Format (
						"Message element named '{0}:{1}' has already been exported.",
						ns, name));
			}
				
			//Create the element for "parameters"
			XmlSchemaElement schema_element = new XmlSchemaElement ();
			schema_element.Name = name;

			XmlSchemaComplexType complex_type = new XmlSchemaComplexType ();
			//Generate Sequence representing the message/parameters
			//FIXME: MessageContractAttribute
		
			XmlSchemaSequence sequence = new XmlSchemaSequence ();
			XmlSchemaElement element = null;

			if (msgbody.ReturnValue == null) {
				//parameters
				foreach (MessagePartDescription part in msgbody.Parts) {
					if (part.Type == null)
						//FIXME: Eg. when WsdlImporter is used to import a wsdl
						throw new NotImplementedException ();
					
					element = GetSchemaElementForPart (part, xs);
					sequence.Items.Add (element);
				}
			} else {
				//ReturnValue
				if (msgbody.ReturnValue.Type != typeof (void)) {
					element = GetSchemaElementForPart (msgbody.ReturnValue, xs);
					sequence.Items.Add (element);
				}
			}

			complex_type.Particle = sequence;
			schema_element.SchemaType = complex_type;

			xs.Items.Add (schema_element);
			GeneratedXmlSchemas.Reprocess (xs);

			return new QName (schema_element.Name, xs.TargetNamespace);
		}
 private bool IsSequenceFromChoice(XmlSchemaSequence derivedSequence, XmlSchemaChoice baseChoice)
 {
     decimal num;
     decimal num2;
     this.CalculateSequenceRange(derivedSequence, out num, out num2);
     if (!this.IsValidOccurrenceRangeRestriction(num, num2, baseChoice.MinOccurs, baseChoice.MaxOccurs) || (derivedSequence.Items.Count > baseChoice.Items.Count))
     {
         return false;
     }
     for (int i = 0; i < derivedSequence.Items.Count; i++)
     {
         if (this.GetMappingParticle((XmlSchemaParticle) derivedSequence.Items[i], baseChoice.Items) < 0)
         {
             return false;
         }
     }
     return true;
 }
 private XmlSchemaParticle CannonicalizeAll(XmlSchemaAll all, bool root, bool substitution)
 {
     if (all.Items.Count > 0)
     {
         XmlSchemaAll all2 = new XmlSchemaAll {
             MinOccurs = all.MinOccurs,
             MaxOccurs = all.MaxOccurs,
             SourceUri = all.SourceUri,
             LineNumber = all.LineNumber,
             LinePosition = all.LinePosition
         };
         for (int i = 0; i < all.Items.Count; i++)
         {
             XmlSchemaParticle item = this.CannonicalizeParticle((XmlSchemaElement) all.Items[i], false, substitution);
             if (item != XmlSchemaParticle.Empty)
             {
                 all2.Items.Add(item);
             }
         }
         all = all2;
     }
     if (all.Items.Count == 0)
     {
         return XmlSchemaParticle.Empty;
     }
     if (root && (all.Items.Count == 1))
     {
         XmlSchemaSequence sequence = new XmlSchemaSequence {
             MinOccurs = all.MinOccurs,
             MaxOccurs = all.MaxOccurs
         };
         sequence.Items.Add((XmlSchemaParticle) all.Items[0]);
         return sequence;
     }
     if ((!root && (all.Items.Count == 1)) && ((all.MinOccurs == 1M) && (all.MaxOccurs == 1M)))
     {
         return (XmlSchemaParticle) all.Items[0];
     }
     if (!root)
     {
         base.SendValidationEvent("Sch_NotAllAlone", all);
         return XmlSchemaParticle.Empty;
     }
     return all;
 }
 private void CompileComplexContentExtension(XmlSchemaComplexType complexType, XmlSchemaComplexContent complexContent, XmlSchemaComplexContentExtension complexExtension)
 {
     XmlSchemaComplexType redefined = null;
     if ((complexType.Redefined != null) && (complexExtension.BaseTypeName == complexType.Redefined.QualifiedName))
     {
         redefined = (XmlSchemaComplexType) complexType.Redefined;
         this.CompileComplexType(redefined);
     }
     else
     {
         redefined = this.GetComplexType(complexExtension.BaseTypeName);
         if (redefined == null)
         {
             base.SendValidationEvent("Sch_UndefBaseExtension", complexExtension.BaseTypeName.ToString(), complexExtension);
             return;
         }
     }
     if (((redefined != null) && (redefined.ElementDecl != null)) && (redefined.ContentType == XmlSchemaContentType.TextOnly))
     {
         base.SendValidationEvent("Sch_NotComplexContent", complexType);
     }
     else
     {
         complexType.SetBaseSchemaType(redefined);
         if ((redefined.FinalResolved & XmlSchemaDerivationMethod.Extension) != XmlSchemaDerivationMethod.Empty)
         {
             base.SendValidationEvent("Sch_BaseFinalExtension", complexType);
         }
         this.CompileLocalAttributes(redefined, complexType, complexExtension.Attributes, complexExtension.AnyAttribute, XmlSchemaDerivationMethod.Extension);
         XmlSchemaParticle contentTypeParticle = redefined.ContentTypeParticle;
         XmlSchemaParticle item = this.CannonicalizeParticle(complexExtension.Particle, true, true);
         if (contentTypeParticle != XmlSchemaParticle.Empty)
         {
             if (item != XmlSchemaParticle.Empty)
             {
                 XmlSchemaSequence particle = new XmlSchemaSequence();
                 particle.Items.Add(contentTypeParticle);
                 particle.Items.Add(item);
                 complexType.SetContentTypeParticle(this.CompileContentTypeParticle(particle, false));
             }
             else
             {
                 complexType.SetContentTypeParticle(contentTypeParticle);
             }
             XmlSchemaContentType contentType = this.GetSchemaContentType(complexType, complexContent, item);
             if (contentType == XmlSchemaContentType.Empty)
             {
                 contentType = redefined.ContentType;
             }
             complexType.SetContentType(contentType);
             if (complexType.ContentType != redefined.ContentType)
             {
                 base.SendValidationEvent("Sch_DifContentType", complexType);
             }
         }
         else
         {
             complexType.SetContentTypeParticle(item);
             complexType.SetContentType(this.GetSchemaContentType(complexType, complexContent, complexType.ContentTypeParticle));
         }
         complexType.SetDerivedBy(XmlSchemaDerivationMethod.Extension);
     }
 }
        //<extension
        //  base = QName
        //  id = ID
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?, ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?)))
        //</extension>
        internal static XmlSchemaComplexContentExtension Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaComplexContentExtension extension = new XmlSchemaComplexContentExtension();

            reader.MoveToElement();

            if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
            {
                error(h, "Should not happen :1: XmlSchemaComplexContentExtension.Read, name=" + reader.Name, null);
                reader.Skip();
                return(null);
            }

            extension.LineNumber   = reader.LineNumber;
            extension.LinePosition = reader.LinePosition;
            extension.SourceUri    = reader.BaseURI;

            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "base")
                {
                    Exception innerex;
                    extension.baseTypeName = XmlSchemaUtil.ReadQNameAttribute(reader, out innerex);
                    if (innerex != null)
                    {
                        error(h, reader.Value + " is not a valid value for base attribute", innerex);
                    }
                }
                else if (reader.Name == "id")
                {
                    extension.Id = reader.Value;
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for extension", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, extension);
                }
            }

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(extension);
            }
            //Content: 1. annotation?,
            //			(2.(group | all | choice | sequence)?, (3.(attribute | attributeGroup)*, 4.anyAttribute?)))
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaComplexContentExtension.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (level <= 1 && reader.LocalName == "annotation")
                {
                    level = 2;                     //Only one annotation
                    XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h);
                    if (annotation != null)
                    {
                        extension.Annotation = annotation;
                    }
                    continue;
                }
                if (level <= 2)
                {
                    if (reader.LocalName == "group")
                    {
                        level = 3;
                        XmlSchemaGroupRef group = XmlSchemaGroupRef.Read(reader, h);
                        if (group != null)
                        {
                            extension.particle = group;
                        }
                        continue;
                    }
                    if (reader.LocalName == "all")
                    {
                        level = 3;
                        XmlSchemaAll all = XmlSchemaAll.Read(reader, h);
                        if (all != null)
                        {
                            extension.particle = all;
                        }
                        continue;
                    }
                    if (reader.LocalName == "choice")
                    {
                        level = 3;
                        XmlSchemaChoice choice = XmlSchemaChoice.Read(reader, h);
                        if (choice != null)
                        {
                            extension.particle = choice;
                        }
                        continue;
                    }
                    if (reader.LocalName == "sequence")
                    {
                        level = 3;
                        XmlSchemaSequence sequence = XmlSchemaSequence.Read(reader, h);
                        if (sequence != null)
                        {
                            extension.particle = sequence;
                        }
                        continue;
                    }
                }
                if (level <= 3)
                {
                    if (reader.LocalName == "attribute")
                    {
                        level = 3;
                        XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader, h);
                        if (attr != null)
                        {
                            extension.Attributes.Add(attr);
                        }
                        continue;
                    }
                    if (reader.LocalName == "attributeGroup")
                    {
                        level = 3;
                        XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader, h);
                        if (attr != null)
                        {
                            extension.attributes.Add(attr);
                        }
                        continue;
                    }
                }
                if (level <= 4 && reader.LocalName == "anyAttribute")
                {
                    level = 5;
                    XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader, h);
                    if (anyattr != null)
                    {
                        extension.AnyAttribute = anyattr;
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(extension);
        }
Example #27
0
        /// <summary>
        /// Gets the class schema.
        /// </summary>
        /// <param name="t">The t.</param>
        /// <returns>schema info</returns>
        public static SchemaInfo GetClassSchema(this Type t)
        {
            var schemaInfo = new SchemaInfo();
            var classType = new XmlSchemaComplexType
                                {
                                    Name = t.Name
                                };

            var attribData = t.GetCustomAttributeDataOfType(typeof(DataContractAttribute));
            if (attribData.NamedArguments != null && attribData.NamedArguments.Count > 0)
            {
                foreach (var p1 in attribData.NamedArguments)
                {
                    switch (p1.MemberInfo.Name)
                    {
                        case "Namespace":
                            schemaInfo.Schema.TargetNamespace = p1.TypedValue.Value as string;
                            break;
                    }
                }
            }

            var sequence = new XmlSchemaSequence();

            classType.Particle = sequence;

            var propList = t.GetProperties();

            foreach (var p1 in propList)
            {
                var el = new XmlSchemaElement
                             {
                                 Name = p1.Name,
                                 MinOccurs = 0
                             };

                var xmlName = p1.PropertyType.XmlName();
                if (xmlName != null)
                {
                    el.SchemaTypeName = xmlName;
                }
                else
                {
                    if (p1.PropertyType.IsListType())
                    {
                        // what is this a list of?
                        if (p1.PropertyType.FullName != null)
                        {
                            var pr = Primitive2Xml.XmlName(InternalType(p1.PropertyType.FullName, false));
                            if (pr != null)
                            {
                                el.SchemaTypeName = new XmlQualifiedName("ArrayOf" + pr.Name);
                                schemaInfo.CustomTypes.Add(el.SchemaTypeName);
                            }
                            else
                            {
                                var schName = InternalType(p1.PropertyType.FullName, true);
                                el.SchemaTypeName = new XmlQualifiedName("ArrayOf" + schName);
                                schemaInfo.CustomTypes.Add(new XmlQualifiedName(schName));
                                schemaInfo.CustomTypes.Add(el.SchemaTypeName);
                            }
                        }
                    }
                    else if (p1.PropertyType.Name.Contains("Nullable"))
                    {
                        // what is this a nullable of?
                        if (p1.PropertyType.FullName != null)
                        {
                            var pr = Primitive2Xml.XmlName(InternalType(p1.PropertyType.FullName, false));
                            if (pr != null)
                            {
                                el.SchemaTypeName = pr;
                            }
                            else
                            {
                                var schName = InternalType(p1.PropertyType.FullName, true);
                                el.SchemaTypeName = new XmlQualifiedName(schName);
                                schemaInfo.CustomTypes.Add(el.SchemaTypeName);
                            }

                            el.IsNillable = true;
                        }
                    }
                    else
                    {
                        el.SchemaTypeName = new XmlQualifiedName(p1.PropertyType.Name);
                        schemaInfo.CustomTypes.Add(el.SchemaTypeName);
                    }
                }

                // get data member
                var attrData = p1.GetCustomAttributeDataOfType(typeof(DataMemberAttribute));
                if (attrData != null && attrData.NamedArguments != null
                    && attrData.NamedArguments.Count > 0)
                {
                    foreach (var pp in attrData.NamedArguments)
                    {
                        switch (pp.MemberInfo.Name)
                        {
                            case "IsRequired":
                                {
                                    var v = (bool)pp.TypedValue.Value;
                                    el.MinOccurs = v ? 1 : 0;
                                }

                                break;
                        }
                    }
                }

                sequence.Items.Add(el);
            }


            schemaInfo.Schema.Items.Add(classType);
            return schemaInfo;
        }
Example #28
0
        internal override bool ValidateDerivationByRestriction(XmlSchemaParticle baseParticle, ValidationEventHandler h, XmlSchema schema, bool raiseError)
        {
            if (this == baseParticle)
            {
                return(true);
            }
            XmlSchemaElement xmlSchemaElement = baseParticle as XmlSchemaElement;

            if (xmlSchemaElement != null)
            {
                if (raiseError)
                {
                    base.error(h, "Invalid sequence paricle derivation.");
                }
                return(false);
            }
            XmlSchemaSequence xmlSchemaSequence = baseParticle as XmlSchemaSequence;

            if (xmlSchemaSequence != null)
            {
                return(this.ValidateOccurenceRangeOK(xmlSchemaSequence, h, schema, raiseError) && ((xmlSchemaSequence.ValidatedMinOccurs == 0m && xmlSchemaSequence.ValidatedMaxOccurs == 0m && base.ValidatedMinOccurs == 0m && base.ValidatedMaxOccurs == 0m) || base.ValidateRecurse(xmlSchemaSequence, h, schema, raiseError)));
            }
            XmlSchemaAll xmlSchemaAll = baseParticle as XmlSchemaAll;

            if (xmlSchemaAll != null)
            {
                XmlSchemaObjectCollection xmlSchemaObjectCollection = new XmlSchemaObjectCollection();
                for (int i = 0; i < this.Items.Count; i++)
                {
                    XmlSchemaElement xmlSchemaElement2 = this.Items[i] as XmlSchemaElement;
                    if (xmlSchemaElement2 == null)
                    {
                        if (raiseError)
                        {
                            base.error(h, "Invalid sequence particle derivation by restriction from all.");
                        }
                        return(false);
                    }
                    foreach (XmlSchemaObject xmlSchemaObject in xmlSchemaAll.Items)
                    {
                        XmlSchemaElement xmlSchemaElement3 = (XmlSchemaElement)xmlSchemaObject;
                        if (xmlSchemaElement3.QualifiedName == xmlSchemaElement2.QualifiedName)
                        {
                            if (xmlSchemaObjectCollection.Contains(xmlSchemaElement3))
                            {
                                if (raiseError)
                                {
                                    base.error(h, "Base element particle is mapped to the derived element particle in a sequence two or more times.");
                                }
                                return(false);
                            }
                            xmlSchemaObjectCollection.Add(xmlSchemaElement3);
                            if (!xmlSchemaElement2.ValidateDerivationByRestriction(xmlSchemaElement3, h, schema, raiseError))
                            {
                                return(false);
                            }
                        }
                    }
                }
                foreach (XmlSchemaObject xmlSchemaObject2 in xmlSchemaAll.Items)
                {
                    XmlSchemaElement xmlSchemaElement4 = (XmlSchemaElement)xmlSchemaObject2;
                    if (!xmlSchemaObjectCollection.Contains(xmlSchemaElement4) && !xmlSchemaElement4.ValidateIsEmptiable())
                    {
                        if (raiseError)
                        {
                            base.error(h, "In base -all- particle, mapping-skipped base element which is not emptiable was found.");
                        }
                        return(false);
                    }
                }
                return(true);
            }
            XmlSchemaAny xmlSchemaAny = baseParticle as XmlSchemaAny;

            if (xmlSchemaAny != null)
            {
                return(base.ValidateNSRecurseCheckCardinality(xmlSchemaAny, h, schema, raiseError));
            }
            XmlSchemaChoice xmlSchemaChoice = baseParticle as XmlSchemaChoice;

            return(xmlSchemaChoice == null || base.ValidateSeqRecurseMapSumCommon(xmlSchemaChoice, h, schema, false, true, raiseError));
        }
Example #29
0
        internal static XmlSchemaSequence Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaSequence xmlSchemaSequence = new XmlSchemaSequence();

            reader.MoveToElement();
            if (reader.NamespaceURI != "http://www.w3.org/2001/XMLSchema" || reader.LocalName != "sequence")
            {
                XmlSchemaObject.error(h, "Should not happen :1: XmlSchemaSequence.Read, name=" + reader.Name, null);
                reader.Skip();
                return(null);
            }
            xmlSchemaSequence.LineNumber   = reader.LineNumber;
            xmlSchemaSequence.LinePosition = reader.LinePosition;
            xmlSchemaSequence.SourceUri    = reader.BaseURI;
            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    xmlSchemaSequence.Id = reader.Value;
                }
                else if (reader.Name == "maxOccurs")
                {
                    try
                    {
                        xmlSchemaSequence.MaxOccursString = reader.Value;
                    }
                    catch (Exception innerException)
                    {
                        XmlSchemaObject.error(h, reader.Value + " is an invalid value for maxOccurs", innerException);
                    }
                }
                else if (reader.Name == "minOccurs")
                {
                    try
                    {
                        xmlSchemaSequence.MinOccursString = reader.Value;
                    }
                    catch (Exception innerException2)
                    {
                        XmlSchemaObject.error(h, reader.Value + " is an invalid value for minOccurs", innerException2);
                    }
                }
                else if ((reader.NamespaceURI == string.Empty && reader.Name != "xmlns") || reader.NamespaceURI == "http://www.w3.org/2001/XMLSchema")
                {
                    XmlSchemaObject.error(h, reader.Name + " is not a valid attribute for sequence", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, xmlSchemaSequence);
                }
            }
            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(xmlSchemaSequence);
            }
            int num = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != "sequence")
                    {
                        XmlSchemaObject.error(h, "Should not happen :2: XmlSchemaSequence.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (num <= 1 && reader.LocalName == "annotation")
                {
                    num = 2;
                    XmlSchemaAnnotation xmlSchemaAnnotation = XmlSchemaAnnotation.Read(reader, h);
                    if (xmlSchemaAnnotation != null)
                    {
                        xmlSchemaSequence.Annotation = xmlSchemaAnnotation;
                    }
                }
                else
                {
                    if (num <= 2)
                    {
                        if (reader.LocalName == "element")
                        {
                            num = 2;
                            XmlSchemaElement xmlSchemaElement = XmlSchemaElement.Read(reader, h);
                            if (xmlSchemaElement != null)
                            {
                                xmlSchemaSequence.items.Add(xmlSchemaElement);
                            }
                            continue;
                        }
                        if (reader.LocalName == "group")
                        {
                            num = 2;
                            XmlSchemaGroupRef xmlSchemaGroupRef = XmlSchemaGroupRef.Read(reader, h);
                            if (xmlSchemaGroupRef != null)
                            {
                                xmlSchemaSequence.items.Add(xmlSchemaGroupRef);
                            }
                            continue;
                        }
                        if (reader.LocalName == "choice")
                        {
                            num = 2;
                            XmlSchemaChoice xmlSchemaChoice = XmlSchemaChoice.Read(reader, h);
                            if (xmlSchemaChoice != null)
                            {
                                xmlSchemaSequence.items.Add(xmlSchemaChoice);
                            }
                            continue;
                        }
                        if (reader.LocalName == "sequence")
                        {
                            num = 2;
                            XmlSchemaSequence xmlSchemaSequence2 = XmlSchemaSequence.Read(reader, h);
                            if (xmlSchemaSequence2 != null)
                            {
                                xmlSchemaSequence.items.Add(xmlSchemaSequence2);
                            }
                            continue;
                        }
                        if (reader.LocalName == "any")
                        {
                            num = 2;
                            XmlSchemaAny xmlSchemaAny = XmlSchemaAny.Read(reader, h);
                            if (xmlSchemaAny != null)
                            {
                                xmlSchemaSequence.items.Add(xmlSchemaAny);
                            }
                            continue;
                        }
                    }
                    reader.RaiseInvalidElementError();
                }
            }
            return(xmlSchemaSequence);
        }
Example #30
0
        //<choice
        //  id = ID
        //  maxOccurs =  (nonNegativeInteger | unbounded)  : 1
        //  minOccurs = nonNegativeInteger : 1
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?, (element | group | choice | sequence | any)*)
        //</choice>
        internal static XmlSchemaChoice Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaChoice choice = new XmlSchemaChoice();

            reader.MoveToElement();

            if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
            {
                error(h, "Should not happen :1: XmlSchemaChoice.Read, name=" + reader.Name, null);
                reader.SkipToEnd();
                return(null);
            }

            choice.LineNumber   = reader.LineNumber;
            choice.LinePosition = reader.LinePosition;
            choice.SourceUri    = reader.BaseURI;

            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    choice.Id = reader.Value;
                }
                else if (reader.Name == "maxOccurs")
                {
                    try
                    {
                        choice.MaxOccursString = reader.Value;
                    }
                    catch (Exception e)
                    {
                        error(h, reader.Value + " is an invalid value for maxOccurs", e);
                    }
                }
                else if (reader.Name == "minOccurs")
                {
                    try
                    {
                        choice.MinOccursString = reader.Value;
                    }
                    catch (Exception e)
                    {
                        error(h, reader.Value + " is an invalid value for minOccurs", e);
                    }
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for choice", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, choice);
                }
            }

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(choice);
            }

            //  Content: (annotation?, (element | group | choice | sequence | any)*)
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaChoice.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (level <= 1 && reader.LocalName == "annotation")
                {
                    level = 2;                     //Only one annotation
                    XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h);
                    if (annotation != null)
                    {
                        choice.Annotation = annotation;
                    }
                    continue;
                }
                if (level <= 2)
                {
                    if (reader.LocalName == "element")
                    {
                        level = 2;
                        XmlSchemaElement element = XmlSchemaElement.Read(reader, h);
                        if (element != null)
                        {
                            choice.items.Add(element);
                        }
                        continue;
                    }
                    if (reader.LocalName == "group")
                    {
                        level = 2;
                        XmlSchemaGroupRef group = XmlSchemaGroupRef.Read(reader, h);
                        if (group != null)
                        {
                            choice.items.Add(group);
                        }
                        continue;
                    }
                    if (reader.LocalName == "choice")
                    {
                        level = 2;
                        XmlSchemaChoice ch = XmlSchemaChoice.Read(reader, h);
                        if (ch != null)
                        {
                            choice.items.Add(ch);
                        }
                        continue;
                    }
                    if (reader.LocalName == "sequence")
                    {
                        level = 2;
                        XmlSchemaSequence sequence = XmlSchemaSequence.Read(reader, h);
                        if (sequence != null)
                        {
                            choice.items.Add(sequence);
                        }
                        continue;
                    }
                    if (reader.LocalName == "any")
                    {
                        level = 2;
                        XmlSchemaAny any = XmlSchemaAny.Read(reader, h);
                        if (any != null)
                        {
                            choice.items.Add(any);
                        }
                        continue;
                    }
                }
                reader.RaiseInvalidElementError();
            }
            return(choice);
        }
Example #31
0
        private string GenExportedXSD(string stnName, PdeExports pdeExports)
        {
            // initialize schema
            string schemaNamespace = "http://www.w3.org/2001/XMLSchema";

            Schema.XmlSchema expSchema = new Schema.XmlSchema();

            // create STN node (root node)
            Schema.XmlSchemaSequence stnElementSequence = CreateSequenceElement(expSchema, stnName);
            Schema.XmlSchemaAll      field = null;
            Schema.XmlSchemaAll      table = null;

            foreach (DomainExportItem expDomain in pdeExports.Items)
            {
                if (expDomain.Items == null || expDomain.Items.Count == 0)
                {
                    continue;
                }

                foreach (ExportItem expItem in expDomain.Items)
                {
                    if (!expItem.IsUsed)
                    {
                        continue;
                    }

                    switch (expItem.MapType)
                    {
                    case MapType.SingleCell:
                        #region field
                        if (field == null)
                        {
                            field = CreateElement(stnElementSequence, MarkupConstant.PdeExportField);
                        }

                        // create field informations
                        Schema.XmlSchemaElement fieldElement = new Schema.XmlSchemaElement();
                        fieldElement.Name           = expItem.EncodeTreeNodeName;
                        fieldElement.SchemaTypeName = new System.Xml.XmlQualifiedName(GetXsdDataType(expItem.DataType), schemaNamespace);
                        field.Items.Add(fieldElement);
                        #endregion
                        break;

                    case MapType.Table:
                        #region table
                        if (table == null)
                        {
                            table = CreateElement(stnElementSequence, MarkupConstant.PdeExportTable);
                        }

                        // create table informations
                        Schema.XmlSchemaElement tableElement = new Schema.XmlSchemaElement();
                        tableElement.MinOccurs       = 0;
                        tableElement.MaxOccursString = "unbounded";
                        tableElement.Name            = expItem.EncodeTreeNodeName;
                        table.Items.Add(tableElement);

                        Schema.XmlSchemaComplexType tableElementType = new Schema.XmlSchemaComplexType();
                        tableElementType.IsMixed = false;
                        Schema.XmlSchemaAll tableElementAll = new Schema.XmlSchemaAll();
                        tableElementType.Particle = tableElementAll;
                        tableElement.SchemaType   = tableElementType;

                        // gen column informations
                        if (expItem.Columns != null && expItem.Columns.Count > 0)
                        {
                            foreach (ColumnExportItem col in expItem.Columns)
                            {
                                if (!col.IsUsed)
                                {
                                    continue;
                                }
                                Schema.XmlSchemaElement colElement = new Schema.XmlSchemaElement();
                                colElement.Name           = col.EncodeTreeNodeName;
                                colElement.SchemaTypeName = new System.Xml.XmlQualifiedName(GetXsdDataType(col.DataType), schemaNamespace);
                                tableElementAll.Items.Add(colElement);
                            }
                        }
                        #endregion
                        break;

                    case MapType.Chart:
                        break;

                    default:
                        break;
                    }
                }
            }

            // complie schema
            expSchema.Compile(new Schema.ValidationEventHandler(ValidationEventHandler));

            // write schem to xsd file
            string xsdFilePath = string.Format("{0}\\{1}.xsd", AssetManager.FileAdapter.TemporaryFolderPath, Guid.NewGuid().ToString());
            using (System.IO.FileStream stream = new System.IO.FileStream(xsdFilePath, System.IO.FileMode.Create))
            {
                expSchema.Write(stream);
                stream.Close();
            }

            return(xsdFilePath);
        }
        /// <include file='doc\SoapSchemaImporter.uex' path='docs/doc[@for="SoapSchemaImporter.ImportMembersMapping3"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public XmlMembersMapping ImportMembersMapping(string name, string ns, SoapSchemaMember[] members, bool hasWrapperElement, Type baseType, bool baseTypeCanBeIndirect) {
            XmlSchemaComplexType type = new XmlSchemaComplexType();
            XmlSchemaSequence seq = new XmlSchemaSequence();
            type.Particle = seq;
            foreach (SoapSchemaMember member in members) {
                XmlSchemaElement element = new XmlSchemaElement();
                element.Name = member.MemberName;
                element.SchemaTypeName = member.MemberType;
                seq.Items.Add(element);
            }

            CodeIdentifiers identifiers = new CodeIdentifiers();
            identifiers.UseCamelCasing = true;
            MembersMapping mapping = new MembersMapping();
            mapping.TypeDesc = Scope.GetTypeDesc(typeof(object[]));
            mapping.Members = ImportTypeMembers(type, ns, identifiers);
            mapping.HasWrapperElement = hasWrapperElement;
            
            if (baseType != null) {
                for (int i = 0; i < mapping.Members.Length; i++) {
                    MemberMapping member = mapping.Members[i];
                    if (member.Accessor.Mapping is StructMapping)
                        MakeDerived((StructMapping)member.Accessor.Mapping, baseType, baseTypeCanBeIndirect);
                }
            }
            ElementAccessor accessor = new ElementAccessor();
            accessor.IsSoap = true;
            accessor.Name = name;
            accessor.Namespace = ns;
            accessor.Mapping = mapping;
            accessor.IsNullable = false;
            accessor.Form = XmlSchemaForm.Qualified;

            return new XmlMembersMapping(Scope, accessor, XmlMappingAccess.Read | XmlMappingAccess.Write);
        }
 void Write54_XmlSchemaSequence(XmlSchemaSequence o) {
     if ((object)o == null) return;
     WriteStartElement("sequence");
     
     WriteAttribute(@"id", @"", ((System.String)o.@Id));
     WriteAttribute("minOccurs", "", XmlConvert.ToString(o.MinOccurs));
     WriteAttribute("maxOccurs", "", o.MaxOccurs == decimal.MaxValue ? "unbounded" : XmlConvert.ToString(o.MaxOccurs));
     WriteAttributes((XmlAttribute[])o.@UnhandledAttributes, o);
     Write5_XmlSchemaAnnotation((XmlSchemaAnnotation)o.@Annotation);
     XmlSchemaObjectCollection a = (XmlSchemaObjectCollection)o.@Items;
     if (a != null) {
         for (int ia = 0; ia < a.Count; ia++) {
             XmlSchemaObject ai = (XmlSchemaObject)a[ia];
             if (ai is XmlSchemaAny) {
                 Write53_XmlSchemaAny((XmlSchemaAny)ai);
             }
             else if (ai is XmlSchemaSequence) {
                 Write54_XmlSchemaSequence((XmlSchemaSequence)ai);
             }
             else if (ai is XmlSchemaChoice) {
                 Write52_XmlSchemaChoice((XmlSchemaChoice)ai);
             }
             else if (ai is XmlSchemaElement) {
                 Write46_XmlSchemaElement((XmlSchemaElement)ai);
             }
             else if (ai is XmlSchemaGroupRef) {
                 Write55_XmlSchemaGroupRef((XmlSchemaGroupRef)ai);
             }
         }
     }
     WriteEndElement();
 }
 private bool IsSequenceFromChoice(XmlSchemaSequence derivedSequence, XmlSchemaChoice baseChoice) {
     decimal minOccurs, maxOccurs;
     minOccurs = derivedSequence.MinOccurs * derivedSequence.Items.Count;
     if (derivedSequence.MaxOccurs == decimal.MaxValue) {
         maxOccurs = decimal.MaxValue;
     }
     else {
         maxOccurs = derivedSequence.MaxOccurs * derivedSequence.Items.Count;
     }
     if (!IsValidOccurrenceRangeRestriction(minOccurs, maxOccurs, baseChoice.MinOccurs, baseChoice.MaxOccurs) || derivedSequence.Items.Count > baseChoice.Items.Count) {
         return false;
     }
     for (int i = 0; i < derivedSequence.Items.Count; ++i) {
         if (GetMappingParticle((XmlSchemaParticle)derivedSequence.Items[i], baseChoice.Items) < 0)
             return false;
     }
     return true;
 }
 private void CalculateSequenceRange(XmlSchemaSequence sequence, out decimal minOccurs, out decimal maxOccurs)
 {
     minOccurs = 0M;
     maxOccurs = 0M;
     for (int i = 0; i < sequence.Items.Count; i++)
     {
         XmlSchemaParticle particle = (XmlSchemaParticle) sequence.Items[i];
         minOccurs += particle.MinOccurs;
         if (particle.MaxOccurs == 79228162514264337593543950335M)
         {
             maxOccurs = 79228162514264337593543950335M;
         }
         else if (maxOccurs != 79228162514264337593543950335M)
         {
             maxOccurs += particle.MaxOccurs;
         }
     }
     minOccurs *= sequence.MinOccurs;
     if (sequence.MaxOccurs == 79228162514264337593543950335M)
     {
         maxOccurs = 79228162514264337593543950335M;
     }
     else if (maxOccurs != 79228162514264337593543950335M)
     {
         maxOccurs *= sequence.MaxOccurs;
     }
 }
        private void CompileComplexContentExtension(XmlSchemaComplexType complexType, XmlSchemaComplexContent complexContent, XmlSchemaComplexContentExtension complexExtension) {
            XmlSchemaComplexType baseType = null;
            if (complexType.Redefined != null && complexExtension.BaseTypeName == complexType.Redefined.QualifiedName) {
                baseType = (XmlSchemaComplexType)complexType.Redefined;
                CompileComplexType(baseType);
            }
            else {
                baseType = GetComplexType(complexExtension.BaseTypeName);
                if (baseType == null) {
                    SendValidationEvent(Res.Sch_UndefBaseExtension, complexExtension.BaseTypeName.ToString(), complexExtension);   
                    return;
                }
            }
            if ((baseType.FinalResolved & XmlSchemaDerivationMethod.Extension) != 0) {
                SendValidationEvent(Res.Sch_BaseFinalExtension, complexType);
            }
            CompileLocalAttributes(baseType, complexType, complexExtension.Attributes, complexExtension.AnyAttribute, XmlSchemaDerivationMethod.Extension);

            XmlSchemaParticle baseParticle = baseType.ContentTypeParticle;
            XmlSchemaParticle extendedParticle = CannonicalizeParticle(complexExtension.Particle, true);
            if (baseParticle != XmlSchemaParticle.Empty) {
                if (extendedParticle != XmlSchemaParticle.Empty) {
                    XmlSchemaSequence compiledParticle = new XmlSchemaSequence();
                    compiledParticle.Items.Add(baseParticle);
                    compiledParticle.Items.Add(extendedParticle);
                    complexType.SetContentTypeParticle(CompileContentTypeParticle(compiledParticle));
                }
                else {
                    complexType.SetContentTypeParticle(baseParticle);
                }
            }
            else {
                complexType.SetContentTypeParticle(extendedParticle);
            }
            XmlSchemaContentType contentType = GetSchemaContentType(complexType, complexContent, extendedParticle);
            if (contentType == XmlSchemaContentType.Empty) { //Derived content type is empty, Get ContentType from base
                contentType = baseType.ContentType;
                // In case of a simple base type (content type is TextOnly) the derived type
                //   will be the same as the base type. So set the same content type and then also
                //   set the same data type.
                if (contentType == XmlSchemaContentType.TextOnly) {
                    complexType.SetDatatype(baseType.Datatype);
                }
            }
            complexType.SetContentType(contentType);

            if (baseType.ContentType != XmlSchemaContentType.Empty && complexType.ContentType != baseType.ContentType) { //If base is empty, do not check
                SendValidationEvent(Res.Sch_DifContentType, complexType);
                return;
            }
            complexType.SetBaseSchemaType(baseType);
            complexType.SetDerivedBy(XmlSchemaDerivationMethod.Extension);
        }
 private bool IsSequenceFromAll(XmlSchemaSequence derivedSequence, XmlSchemaAll baseAll)
 {
     if (!this.IsValidOccurrenceRangeRestriction(derivedSequence, baseAll) || (derivedSequence.Items.Count > baseAll.Items.Count))
     {
         return false;
     }
     BitSet set = new BitSet(baseAll.Items.Count);
     for (int i = 0; i < derivedSequence.Items.Count; i++)
     {
         int mappingParticle = this.GetMappingParticle((XmlSchemaParticle) derivedSequence.Items[i], baseAll.Items);
         if (mappingParticle < 0)
         {
             return false;
         }
         if (set[mappingParticle])
         {
             return false;
         }
         set.Set(mappingParticle);
     }
     for (int j = 0; j < baseAll.Items.Count; j++)
     {
         if (!set[j] && !this.IsParticleEmptiable((XmlSchemaParticle) baseAll.Items[j]))
         {
             return false;
         }
     }
     return true;
 }
Example #38
0
		internal static XmlSchema BuildSchema (DiscoveryVersion version)
		{
			var schema = new XmlSchema () { TargetNamespace = version.Namespace };

			var anyAttr = new XmlSchemaAnyAttribute () { Namespace = "##other", ProcessContents = XmlSchemaContentProcessing.Lax };

			var probePart = new XmlSchemaSequence ();
			probePart.Items.Add (new XmlSchemaElement () { RefName = new XmlQualifiedName ("Types", version.Namespace), MinOccurs = 0 });
			probePart.Items.Add (new XmlSchemaElement () { RefName = new XmlQualifiedName ("Scopes", version.Namespace), MinOccurs = 0 });
			probePart.Items.Add (new XmlSchemaAny () { MinOccurs = 0, MaxOccursString = "unbounded", Namespace = "##other", ProcessContents = XmlSchemaContentProcessing.Lax });
			var ct = new XmlSchemaComplexType () { Name = "ProbeType", Particle = probePart, AnyAttribute = anyAttr };
			schema.Items.Add (ct);

			schema.Items.Add (new XmlSchemaSimpleType () { Name = "QNameListType", Content = new XmlSchemaSimpleTypeList () { ItemTypeName = new XmlQualifiedName ("QName", XmlSchema.Namespace) } });

			var scr = new XmlSchemaSimpleContentRestriction () { BaseTypeName = new XmlQualifiedName ("UriListType", version.Namespace), AnyAttribute = anyAttr };
			scr.Attributes.Add (new XmlSchemaAttribute () { Name = "matchBy", SchemaTypeName = new XmlQualifiedName ("anyURI", XmlSchema.Namespace) });
			schema.Items.Add (new XmlSchemaComplexType () { Name = "ScopesType", ContentModel = new XmlSchemaSimpleContent () { Content = scr } });

			schema.Items.Add (new XmlSchemaSimpleType () { Name = "UriListType", Content = new XmlSchemaSimpleTypeList () { ItemTypeName = new XmlQualifiedName ("anyURI", XmlSchema.Namespace) } });

			schema.Items.Add (new XmlSchemaElement () { Name = "Types", SchemaTypeName = new XmlQualifiedName ("QNameListType", version.Namespace) });
			schema.Items.Add (new XmlSchemaElement () { Name = "Scopes", SchemaTypeName = new XmlQualifiedName ("ScopesType", version.Namespace) });

			return schema;
		}
 private XmlSchemaParticle CannonicalizeSequence(XmlSchemaSequence sequence, bool root, bool substitution)
 {
     if (sequence.Items.Count > 0)
     {
         XmlSchemaSequence sequence2 = new XmlSchemaSequence {
             MinOccurs = sequence.MinOccurs,
             MaxOccurs = sequence.MaxOccurs
         };
         for (int i = 0; i < sequence.Items.Count; i++)
         {
             XmlSchemaParticle item = this.CannonicalizeParticle((XmlSchemaParticle) sequence.Items[i], false, substitution);
             if (item != XmlSchemaParticle.Empty)
             {
                 if (((item.MinOccurs == 1M) && (item.MaxOccurs == 1M)) && (item is XmlSchemaSequence))
                 {
                     XmlSchemaSequence sequence3 = (XmlSchemaSequence) item;
                     for (int j = 0; j < sequence3.Items.Count; j++)
                     {
                         sequence2.Items.Add(sequence3.Items[j]);
                     }
                 }
                 else
                 {
                     sequence2.Items.Add(item);
                 }
             }
         }
         sequence = sequence2;
     }
     if (sequence.Items.Count == 0)
     {
         return XmlSchemaParticle.Empty;
     }
     if ((!root && (sequence.Items.Count == 1)) && ((sequence.MinOccurs == 1M) && (sequence.MaxOccurs == 1M)))
     {
         return (XmlSchemaParticle) sequence.Items[0];
     }
     return sequence;
 }
Example #40
0
 public static XmlSchemaComplexType GetTypedTableSchema(XmlSchemaSet xs)
 {
     XmlSchemaComplexType type = new XmlSchemaComplexType();
     XmlSchemaSequence sequence = new XmlSchemaSequence();
     DsNpStat stat = new DsNpStat();
     xs.Add(stat.GetSchemaSerializable());
     XmlSchemaAny item = new XmlSchemaAny {
         Namespace = "http://www.w3.org/2001/XMLSchema",
         MinOccurs = 0M,
         MaxOccurs = 79228162514264337593543950335M,
         ProcessContents = XmlSchemaContentProcessing.Lax
     };
     sequence.Items.Add(item);
     XmlSchemaAny any2 = new XmlSchemaAny {
         Namespace = "urn:schemas-microsoft-com:xml-diffgram-v1",
         MinOccurs = 1M,
         ProcessContents = XmlSchemaContentProcessing.Lax
     };
     sequence.Items.Add(any2);
     XmlSchemaAttribute attribute = new XmlSchemaAttribute {
         Name = "namespace",
         FixedValue = stat.Namespace
     };
     type.Attributes.Add(attribute);
     XmlSchemaAttribute attribute2 = new XmlSchemaAttribute {
         Name = "tableTypeName",
         FixedValue = "V_NpStatDataTable"
     };
     type.Attributes.Add(attribute2);
     type.Particle = sequence;
     return type;
 }
		//Exports <xs:type for SMMessage
		//FIXME: complex type for this can be made static
		QName ExportTypeMessage ()
		{
			XmlSchema xs = GetSchema ("http://schemas.microsoft.com/Message");
			QName qname = new QName ("MessageBody", xs.TargetNamespace);

			foreach (XmlSchemaObject o in xs.Items) {
				XmlSchemaComplexType ct = o as XmlSchemaComplexType;
				if (ct == null)
					continue;

				if (ct.Name == "MessageBody")
					//Already exported
					return qname;
			}

			XmlSchemaComplexType complex_type = new XmlSchemaComplexType ();
			complex_type.Name = "MessageBody";
			XmlSchemaSequence sequence = new XmlSchemaSequence ();

			XmlSchemaAny any = new XmlSchemaAny ();
			any.MinOccurs = 0;
			any.MaxOccursString = "unbounded";
			any.Namespace = "##any";

			sequence.Items.Add (any);
			complex_type.Particle = sequence;

			xs.Items.Add (complex_type);
			GeneratedXmlSchemas.Reprocess (xs);
			
			return qname;
		}
        /// <summary>
        /// Returns an XmlSchema for the Suggestion that describes the
        /// XML representation of the output that is produced by the WriteXml
        /// method and consumed by the ReadXmlMethod 
        /// </summary>
        /// <returns>XmlSchema for the Suggestion</returns>
        public System.Xml.Schema.XmlSchema GetSchema()
        {
            // This method must return
            //<xs:schema
            //        id="types"
            //        elementFormDefault="qualified"
            //        version="Exchange2007"
            //        xmlns:t=".../types"
            //        targetNamespace=".../types"
            //        xmlns:tns=".../types"
            //        xmlns:xs="http://www.w3.org/2001/XMLSchema">
            // <xs:complexType name="Suggestion">
            //  <xs:sequence>
            //    <xs:element minOccurs="1" maxOccurs="1" name="MeetingTime"
            //                type="xs:dateTime" />
            //    <xs:element minOccurs="1" maxOccurs="1" name="IsWorkTime"
            //                type="xs:boolean" />
            //    <xs:element minOccurs="1" maxOccurs="1"
            //                name="SuggestionQuality"
            //                type="t:SuggestionQuality" />
            //    <xs:element minOccurs="0" maxOccurs="1"
            //                name="AttendeeConflictDataArray"
            //                type="t:ArrayOfAttendeeConflictData" />
            //  </xs:sequence>
            // </xs:complexType>

            string xsTypes =
                "http://schemas.microsoft.com/exchange/services/2006/types";
            string xsSchema = "http://www.w3.org/2001/XMLSchema";

            XmlSchema schema = new XmlSchema();
            schema.Id = "types";
            schema.ElementFormDefault = XmlSchemaForm.Qualified;
            schema.Version = "Exchange2007";
            schema.TargetNamespace = xsTypes;

            // <xs:complexType ... >
            XmlSchemaComplexType xmlct1 = new XmlSchemaComplexType();
            schema.Items.Add(xmlct1);
            xmlct1.Name = "Suggestion";

            //  <xs:sequence ... >
            XmlSchemaSequence xmlsq1 = new XmlSchemaSequence();
            xmlct1.Particle = xmlsq1;

            //    <xs:element ... name="MeetingTime" ... />
            XmlSchemaElement xmle1 = new XmlSchemaElement();
            xmlsq1.Items.Add(xmle1);
            xmle1.Name = "MeetingTime";
            xmle1.MinOccurs = 1;
            xmle1.MaxOccurs = 1;
            xmle1.SchemaTypeName = new XmlQualifiedName("dateTime", xsSchema);

            //    <xs:element ... name="IsWorkTime" ... />
            XmlSchemaElement xmle2 = new XmlSchemaElement();
            xmlsq1.Items.Add(xmle2);
            xmle2.Name = "IsWorkTime";
            xmle2.MinOccurs = 1;
            xmle2.MaxOccurs = 1;
            xmle2.SchemaTypeName = new XmlQualifiedName("boolean", xsSchema);

            //    <xs:element ... name="SuggestionQuality" ... />
            XmlSchemaElement xmle3 = new XmlSchemaElement();
            xmlsq1.Items.Add(xmle3);
            xmle3.Name = "SuggestionQuality";
            xmle3.MinOccurs = 1;
            xmle3.MaxOccurs = 1;
            xmle3.SchemaTypeName = new XmlQualifiedName(
                "SuggestionQuality", xsTypes);

            //    <xs:element ... name="AttendeeConflictDataArray" ... />
            XmlSchemaElement xmle4 = new XmlSchemaElement();
            xmlsq1.Items.Add(xmle4);
            xmle4.Name = "AttendeeConflictDataArray";
            xmle4.MinOccurs = 0;
            xmle4.MaxOccurs = 1;
            xmle4.SchemaTypeName = new XmlQualifiedName(
                "ArrayOfAttendeeConflictData", xsTypes);

            return schema;
        }
Example #43
0
 public static XmlSchemaComplexType GetTypedDataSetSchema(XmlSchemaSet xs)
 {
     DsNpStat stat = new DsNpStat();
     XmlSchemaComplexType type = new XmlSchemaComplexType();
     XmlSchemaSequence sequence = new XmlSchemaSequence();
     xs.Add(stat.GetSchemaSerializable());
     XmlSchemaAny item = new XmlSchemaAny {
         Namespace = stat.Namespace
     };
     sequence.Items.Add(item);
     type.Particle = sequence;
     return type;
 }
Example #44
0
        private string SchemaSearching(XmlSchema xmlSchema, string inputParamType)
        {
            string       returnval = null;
            XmlGenerator xmlGen    = new XmlGenerator();

            foreach (object item in xmlSchema.Items)
            {
                System.Xml.Schema.XmlSchemaElement schemaElement = item as System.Xml.Schema.XmlSchemaElement;
                if (schemaElement != null)
                {
                    if (schemaElement.Name == inputParamType)
                    {
                        returnval = xmlGen.GenerateXmlString(schemaElement, xmlSchema);
                        break;//The parameter was found no need to go through rest of elements
                    }
                }
                else
                { //This is a complex Type
                    System.Xml.Schema.XmlSchemaComplexType complexType = item as System.Xml.Schema.XmlSchemaComplexType;
                    if (complexType != null)
                    {
                        if (complexType.Name == inputParamType)
                        {
                            Logger.Text += "Complex Type Name : " + complexType.Name + "\r\n";
                            System.Xml.Schema.XmlSchemaParticle particle  = complexType.Particle;
                            System.Xml.Schema.XmlSchemaSequence sequence  = particle as System.Xml.Schema.XmlSchemaSequence;
                            System.Xml.Schema.XmlSchemaAll      schemaall = particle as System.Xml.Schema.XmlSchemaAll;
                            if (sequence != null)
                            {
                                foreach (System.Xml.Schema.XmlSchemaElement childElement in sequence.Items)
                                {
                                    string parameterName = childElement.Name;
                                    string parameterType = childElement.SchemaTypeName.Name;
                                    returnval = '<' + complexType.Name + '>' + xmlGen.GenerateXmlString(childElement, xmlSchema) + "</" + complexType.Name + '>';
                                }
                            }
                            else
                            {
                                if (schemaall != null)
                                {
                                    returnval = '<' + complexType.Name + '>' + xmlGen.GenerateXmlString(schemaall, xmlSchema) + "</" + complexType.Name + '>';
                                }
                                else
                                {
                                    System.Xml.Schema.XmlSchemaComplexContent cmplxContent = null;
                                    if (cmplxContent != null)
                                    {
                                        returnval = '<' + complexType.Name + '>' + xmlGen.GenerateXmlString(cmplxContent, xmlSchema) + "</" + complexType.Name + '>';;
                                    }
                                }
                            }
                            break;  //The parameter was found no need to go through rest of elements
                        }
                    }
                    else
                    {   //Nothing to do?
                        //System.Xml.Schema.XmlSchemaSimpleType simpleType = item as System.Xml.Schema.XmlSchemaSimpleType;
                    }
                }
            }
            return(returnval);
        }
Example #45
0
        /**************************************************************************
        The V2.0 (no V1.0 or V1.1) WSDL for Untyped DataTable being returned as a result (no parameters)
        <s:element name="anyUserSpecifiedMethodName">
            <!--  This is where parameters go -->
            <s:complexType /> 
        </s:element>
        <s:element name="anyUserSpecifiedMethodName"+"Response">
            <s:complexType>
                <s:sequence>
                    <s:element minOccurs="0" maxOccurs="1" name="anyUserSpecifiedMethodName"+"Result">
                        <s:complexType>
                            <s:sequence>
                                <s:any minOccurs="0" maxOccurs="unbounded" namespace="http://www.w3.org/2001/XMLSchema" processContents="lax" /> 
                                <s:any minOccurs="1" namespace="urn:schemas-microsoft-com:xml-diffgram-v1" processContents="lax" /> 
                            </s:sequence>
                        </s:complexType>
                    </s:element>
                </s:sequence>
            </s:complexType>
        </s:element>

        Typed DataTable is not supported in WSDL (SQLBU 444636)

        either fails because xsd generates its typed DataTable with an internal parameterless ctor
        
        or System.NullReferenceException: Object reference not set to an instance of an object.   (if namespace of StronglyTyped DataTable is not set)
           at System.Data.XmlTreeGen.FindTargetNamespace(DataTable table)

        or System.InvalidOperationException: Schema Id is missing. The schema returned from WebServiceDataSetServer.Service+StudentsDataTable.GetSchema() must have an Id.
           at System.Xml.Serialization.SerializableMapping.RetrieveSerializableSchema()
        *****************************************************************************/
        public static XmlSchemaComplexType GetDataTableSchema(XmlSchemaSet schemaSet) {
            XmlSchemaComplexType type = new XmlSchemaComplexType();
            XmlSchemaSequence sequence = new XmlSchemaSequence();
            XmlSchemaAny any = new XmlSchemaAny();
            any.Namespace = XmlSchema.Namespace;
            any.MinOccurs = 0;
            any.MaxOccurs = Decimal.MaxValue;
            any.ProcessContents = XmlSchemaContentProcessing.Lax;
            sequence.Items.Add(any);

            any = new XmlSchemaAny();
            any.Namespace = Keywords.DFFNS;
            any.MinOccurs = 1; // when recognizing WSDL - MinOccurs="0" denotes DataSet, a MinOccurs="1" for DataTable
            any.ProcessContents = XmlSchemaContentProcessing.Lax;
            sequence.Items.Add(any);

            type.Particle = sequence;

            return type;
        }
 private bool IsElementFromGroupBase(XmlSchemaElement derivedElement, XmlSchemaGroupBase baseGroupBase) {
     if (baseGroupBase is XmlSchemaSequence) {
         XmlSchemaSequence virtualSeq = new XmlSchemaSequence();
         virtualSeq.MinOccurs = 1;
         virtualSeq.MaxOccurs = 1;
         virtualSeq.Items.Add(derivedElement);
         if (IsGroupBaseFromGroupBase((XmlSchemaGroupBase)virtualSeq, baseGroupBase, true)) {
             return true;
         }
         restrictionErrorMsg = Res.GetString(Res.Sch_ElementFromGroupBase1, derivedElement.QualifiedName.ToString(), derivedElement.LineNumber.ToString(NumberFormatInfo.InvariantInfo), derivedElement.LinePosition.ToString(NumberFormatInfo.InvariantInfo), baseGroupBase.LineNumber.ToString(NumberFormatInfo.InvariantInfo), baseGroupBase.LinePosition.ToString(NumberFormatInfo.InvariantInfo));
     }
     else if (baseGroupBase is XmlSchemaChoice) {
         XmlSchemaChoice virtualChoice = new XmlSchemaChoice();
         virtualChoice.MinOccurs = 1;
         virtualChoice.MaxOccurs = 1;
         virtualChoice.Items.Add(derivedElement);
         if (IsGroupBaseFromGroupBase((XmlSchemaGroupBase)virtualChoice, baseGroupBase, false)) {
             return true;
         }
         restrictionErrorMsg = Res.GetString(Res.Sch_ElementFromGroupBase2, derivedElement.QualifiedName.ToString(), derivedElement.LineNumber.ToString(NumberFormatInfo.InvariantInfo), derivedElement.LinePosition.ToString(NumberFormatInfo.InvariantInfo), baseGroupBase.LineNumber.ToString(NumberFormatInfo.InvariantInfo), baseGroupBase.LinePosition.ToString(NumberFormatInfo.InvariantInfo));
     }
     else if (baseGroupBase is XmlSchemaAll) {
         XmlSchemaAll virtualAll = new XmlSchemaAll();
         virtualAll.MinOccurs = 1;
         virtualAll.MaxOccurs = 1;
         virtualAll.Items.Add(derivedElement);
         if (IsGroupBaseFromGroupBase((XmlSchemaGroupBase)virtualAll, baseGroupBase, true)) {
             return true;
         }
         restrictionErrorMsg = Res.GetString(Res.Sch_ElementFromGroupBase3, derivedElement.QualifiedName.ToString(), derivedElement.LineNumber.ToString(NumberFormatInfo.InvariantInfo), derivedElement.LinePosition.ToString(NumberFormatInfo.InvariantInfo), baseGroupBase.LineNumber.ToString(NumberFormatInfo.InvariantInfo), baseGroupBase.LinePosition.ToString(NumberFormatInfo.InvariantInfo));
     }
     return false;
 }
Example #47
0
        /// <summary>
        /// Gets the list schema.
        /// </summary>
        /// <param name="t">The t.</param>
        /// <returns>schema info</returns>
        public static SchemaInfo GetListSchema(this Type t)
        {
            var schemaInfo = new SchemaInfo();
            var classType = new XmlSchemaComplexType
            {
                Name = "ArrayOf" + t.Name
            };

            var sequence = new XmlSchemaSequence();

            schemaInfo.Schema.Items.Add(classType);
            classType.Particle = sequence;
            sequence.Items.Add(new XmlSchemaElement
                                   {
                                       Name = t.Name,
                                       MinOccurs = 0,
                                       MaxOccursString = "unbounded",
                                       SchemaTypeName = new XmlQualifiedName(t.Name)
                                   });


            return schemaInfo;
        }
 private bool IsSequenceFromAll(XmlSchemaSequence derivedSequence, XmlSchemaAll baseAll) {
     if (!IsValidOccurrenceRangeRestriction(derivedSequence, baseAll) || derivedSequence.Items.Count > baseAll.Items.Count) {
         return false;
     }
     BitSet map = new BitSet(baseAll.Items.Count);
     for (int j = 0; j < derivedSequence.Items.Count; ++j) {
         int i = GetMappingParticle((XmlSchemaParticle)derivedSequence.Items[j], baseAll.Items);
         if (i >= 0) {
             if (map[i]) {
                 return false;
             }
             else {
                 map.Set(i);
             }
         }
         else {
             return false;
         }
     }
     for (int i = 0; i < baseAll.Items.Count; i++) {
         if (!map[i] && !IsParticleEmptiable((XmlSchemaParticle)baseAll.Items[i])) {
             return false;
         }
     }
     return true;
 }