상속: XmlSchemaType
예제 #1
1
        public XmlSchemaElement GetSchema()
        {
            var type = new XmlSchemaComplexType();

            type.Attributes.Add(new XmlSchemaAttribute
                                    {
                                        Name = "refValue",
                                        Use = XmlSchemaUse.Required,
                                        SchemaTypeName =
                                            new XmlQualifiedName("positiveInteger", "http://www.w3.org/2001/XMLSchema")
                                    });

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

            
            var restriction = new XmlSchemaSimpleTypeRestriction
                                  {
                                      BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")
                                  };

            restriction.Facets.Add(new XmlSchemaEnumerationFacet {Value = "years"});
            restriction.Facets.Add(new XmlSchemaEnumerationFacet {Value = "weeks"});
            restriction.Facets.Add(new XmlSchemaEnumerationFacet {Value = "days"});

            var simpleType = new XmlSchemaSimpleType {Content = restriction};


            type.Attributes.Add(new XmlSchemaAttribute
                                    {
                                        Name = "units",
                                        Use = XmlSchemaUse.Required,
                                        SchemaType = simpleType
                                    });


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

            var element = new XmlSchemaElement
                              {
                                  Name = "dicom-age-less-than",
                                  SchemaType = type
                              };

            return element;
        }
예제 #2
0
        //gen new xsd base on selected tables and columns which generated by OSQL.
        private string CreateXsd()
        {
            xmlschema = new sch.XmlSchema();

            //Create the PdeData element
            sch.XmlSchemaElement rootElement = new sch.XmlSchemaElement();
            rootElement.Name = "PdeData";
            xmlschema.Items.Add(rootElement);
            sch.XmlSchemaComplexType rootType = new sch.XmlSchemaComplexType();
            rootType.IsMixed = false;
            sch.XmlSchemaAll rootAll = new sch.XmlSchemaAll();
            rootType.Particle      = rootAll;
            rootElement.SchemaType = rootType;

            for (int i = 0; i < selectedTables.Count; i++)
            {
                rootAll = GenOneTabElement(rootAll, selectedTables[i], selectedColumns[i], tabColsType[i]);
            }

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

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

            return("e:\\temp.xsd");
        }
예제 #3
0
        private sch.XmlSchemaAll GenOneTabElement(sch.XmlSchemaAll curElement, string tableAlias, List <string> tabCols, List <string> tabColTypes)
        {
            sch.XmlSchemaElement rootElement = new sch.XmlSchemaElement();
            rootElement.Name            = tableAlias;
            rootElement.MinOccurs       = 0;
            rootElement.MaxOccursString = "unbounded";
            curElement.Items.Add(rootElement);

            sch.XmlSchemaComplexType rootType = new sch.XmlSchemaComplexType();
            rootType.IsMixed = false;
            sch.XmlSchemaAll rootAll = new sch.XmlSchemaAll();
            rootType.Particle      = rootAll;
            rootElement.SchemaType = rootType;

            for (int i = 0; i < tabCols.Count; i++)
            {
                string colName = tabCols[i];
                string type    = tabColTypes[i];
                sch.XmlSchemaElement column = new sch.XmlSchemaElement();
                column.Name           = colName;
                column.SchemaTypeName = new XmlQualifiedName(type, ns);
                rootAll.Items.Add(column);
            }
            return(rootAll);
        }
		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;
		}
예제 #5
0
        /*public string GenerateXmlString(XmlSchemaParticle root)
         * {
         *  string tag = null;
         *  if (root is XmlSchemaElement)
         *  {
         *      XmlSchemaElement elem = root as XmlSchemaElement;
         *      tag += '<' + elem.Name + '>';
         *      if (elem.RefName.IsEmpty)
         *      { //sequence
         *          XmlSchemaType type = (XmlSchemaType)elem.ElementSchemaType;
         *          //XmlSchemaComplexType complexType = type as XmlSchemaComplexType;
         *          if (type is XmlSchemaComplexType)
         *          {
         *              XmlSchemaComplexType complexType = type as XmlSchemaComplexType;
         *              if (complexType.QualifiedName.IsEmpty)
         *              //if (!((elem.Parent is XmlSchemaComplexType) || (elem.Parent is XmlSchemaSimpleType)))
         *              {
         *                  tag += '<' + elem.Name + '>';
         *                  tag += GenerateXmlString(complexType.ContentTypeParticle);
         *                  tag += "</" + elem.Name + ">";
         *              }*/
        /*else
         * {
         * }*//*
         * }
         * }
         * tag += "</"+elem.Name+">";
         *
         *//*else
         * {  //is it simpletype
         * XmlSchemaSimpleType simpleType = ((XmlSchemaType)elem.ElementSchemaType) as XmlSchemaSimpleType;
         * //SimpleType element restriction, maxinclusive, mininclusive,
         * if (simpleType != null)
         * {  //Need to take care of restriction, list or union types here
         * //simpleType.TypeCode
         *  if (simpleType.Name == null)
         *  {
         *  }
         *  else
         *  {
         *  }
         * }
         * }*//*
         *
         * //}
         *
         *  }
         *  else
         * if (root is XmlSchemaGroupBase)
         * { //It xs:all,
         * XmlSchemaGroupBase baseParticle = root as XmlSchemaGroupBase;
         * //tag += baseParticle.Name
         * foreach (XmlSchemaParticle subParticle in baseParticle.Items)
         * {
         * tag += GenerateXmlString(subParticle);
         * }
         * }
         *  return tag;
         * }*/
        public XmlSchemaObject SearchNode(XmlSchema xs, string name)
        {
            XmlSchemaObject returnval = null;

            foreach (object item in xs.Items)
            {
                System.Xml.Schema.XmlSchemaElement     xse  = item as System.Xml.Schema.XmlSchemaElement;
                System.Xml.Schema.XmlSchemaComplexType xsct = item as System.Xml.Schema.XmlSchemaComplexType;
                if (xse != null)
                {
                    if (xse.Name == name)
                    {
                        returnval = xse;
                    }
                }
                else
                {
                    if (xsct != null)
                    {
                        if (xsct.Name == name)
                        {
                            returnval = xsct;
                        }
                    }
                }
            }
            return(returnval);
        }
예제 #6
0
        private Particle PopulateParticle(ComplexType ct)
        {
            if (ct.ContentModel == null)
            {
                if (ct.Particle == null)
                {
                    ct.Particle = CreateSequence();
                }
                return(ct.Particle);
            }
            ComplexModel cm = ct.ContentModel as ComplexModel;

            if (cm != null)
            {
                ComplexExt ce = cm.Content as ComplexExt;
                if (ce != null)
                {
                    if (ce.Particle == null)
                    {
                        ce.Particle = CreateSequence();
                    }
                    return(ce.Particle);
                }
                ComplexRst cr = cm.Content as ComplexRst;
                if (cr != null)
                {
                    if (cr.Particle == null)
                    {
                        cr.Particle = CreateSequence();
                    }
                    return(cr.Particle);
                }
            }
            throw Error(ct, "Schema inference internal error. The complexType should have been converted to have a complex content.");
        }
예제 #7
0
        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);
        }
예제 #8
0
        XObject[] CreateProtoComplexType(XmlSchemaComplexType complexType) {
            if (complexType.ContentModel != null) {
                if ((complexType.ContentModel as XmlSchemaSimpleContent) != null) {
                    return CreateProtoSimpleContent((complexType.ContentModel as XmlSchemaSimpleContent), complexType.BaseXmlSchemaType).ToArray();
                } else if ((complexType.ContentModel as XmlSchemaComplexContent) != null) {
                    return CreateProtoComplexContent((complexType.ContentModel as XmlSchemaComplexContent), complexType.BaseXmlSchemaType).ToArray();
                } else {
                    throw new Exception("not implemented");
                }
            } else {
                var complexContentExt = new XmlSchemaComplexContentExtension();
                if (complexType.BaseXmlSchemaType != null) {
                    complexContentExt.BaseTypeName = complexType.BaseXmlSchemaType.QualifiedName;
                } else {
                    complexContentExt.BaseTypeName = null;
                }

                if (complexType.Attributes != null) {
                    foreach (var i in complexType.Attributes) {
                        complexContentExt.Attributes.Add(i);
                    }
                }
                complexContentExt.Particle = complexType.Particle;
                var complexContent = new XmlSchemaComplexContent();
                complexContent.Content = complexContentExt;
                return CreateProtoComplexContent(complexContent, complexType.BaseXmlSchemaType).ToArray();
            }
        }
예제 #9
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();
        }
예제 #10
0
 public ChildComplexType(XmlSchemaComplexType complexType, string elementName, string dotnetClassName, string nameSpace, XmlQualifiedName qname)
 {
     this.ComplexType = complexType;
     this.ElementName = elementName;
     this.DotnetClassName = dotnetClassName;
     this.Namespace = nameSpace;
     this.Qname = qname;
 }
예제 #11
0
 static XmlSchemaComplexType() {
     anyType = new XmlSchemaComplexType();
     anyType.SetContentType(XmlSchemaContentType.Mixed);
     anyType.ElementDecl = SchemaElementDecl.CreateAnyTypeElementDecl();
     XmlSchemaAnyAttribute anyAttribute = new XmlSchemaAnyAttribute();
     anyAttribute.BuildNamespaceList(null);
     anyType.SetAttributeWildcard(anyAttribute);
     anyType.ElementDecl.AnyAttribute = anyAttribute;
 }
예제 #12
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");
        }
예제 #13
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;
        }
예제 #14
0
		XmlSchemaComplexType GetStype ()
		{
			XmlSchemaSequence seq = new XmlSchemaSequence ();
			seq.Items.Add (new XmlSchemaAny ());
		
			XmlSchemaComplexType stype = new XmlSchemaComplexType ();
			stype.Particle = seq;
			
			return stype;
		}
		public XmlSchemaElement GetSchema()
		{
			var type = new XmlSchemaComplexType();

			return new XmlSchemaElement
			{
				Name = OperatorTag,
				SchemaType = type
			};
		}
 private void CheckComplexType(XmlQualifiedName typeName, XmlSchemaComplexType type)
 {
     if (type.IsAbstract)
     {
         ThrowTypeCannotBeImportedException(typeName.Name, typeName.Namespace, System.Runtime.Serialization.SR.GetString("AbstractTypeNotSupported"));
     }
     if (type.IsMixed)
     {
         ThrowTypeCannotBeImportedException(typeName.Name, typeName.Namespace, System.Runtime.Serialization.SR.GetString("MixedContentNotSupported"));
     }
 }
예제 #17
0
파일: XsdVisitor.cs 프로젝트: willrawls/arp
        public virtual void VisitComplexType(XmlSchemaComplexType xmlSchemaComplexType)
        {
            //            XmlSchemaParticle particle = xmlSchemaComplexType.ContentTypeParticle;
            //            VisitParticle(particle);

            foreach (XmlSchemaObject attribute in xmlSchemaComplexType.Attributes)
            {
                Dispatch(attribute);
            }
            Dispatch(xmlSchemaComplexType.Particle);
        }
 public Generator(XmlSchemaComplexType xsCoxType,
                  Dictionary<string, string> elementRef,
                  Dictionary<string, string> includePath,
                  List<KeyValuePair<string, string>> elementSubstitutionRef,
                  Dictionary<string, XmlSchemaGroup> elementGroupRef)
 {
     this.includePath = includePath;
     this.elementRef = elementRef;
     this.elementSubstitutionRef = elementSubstitutionRef;
     this.elementGroupRef = elementGroupRef;
     this.setXsd(xsCoxType);
 }
        public override void FixtureInit()
        {
            XmlSchemaCompletionCollection schemas = new XmlSchemaCompletionCollection();
            schemas.Add(SchemaCompletion);
            XmlSchemaCompletion xsdSchemaCompletion = new XmlSchemaCompletion(ResourceManager.ReadXsdSchema());
            schemas.Add(xsdSchemaCompletion);

            string xml = GetSchema();
            int index = xml.IndexOf("type=\"text-type\"");
            index = xml.IndexOf("text-type", index);
            XmlSchemaDefinition schemaDefinition = new XmlSchemaDefinition(schemas, SchemaCompletion);
            schemaComplexType = (XmlSchemaComplexType)schemaDefinition.GetSelectedSchemaObject(xml, index);
        }
예제 #20
0
        private void AddExtensionAttributes(ClassInfo classInfo, XmlSchemaComplexType complex)
        {
            if (complex.ContentModel == null || !(complex.ContentModel.Content is XmlSchemaSimpleContentExtension))
                return;

            var sce = complex.ContentModel.Content as XmlSchemaSimpleContentExtension;

            if (sce.Attributes.Count == 0)
                return;

            AddAttributes(classInfo, sce.Attributes);
            AddValueProperty(classInfo, sce);
        }
예제 #21
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);
        }
		public override void FixtureInit()
		{
			XmlSchemaCompletionDataCollection schemas = new XmlSchemaCompletionDataCollection();
			schemas.Add(SchemaCompletionData);
			XmlSchemaCompletionData xsdSchemaCompletionData = new XmlSchemaCompletionData(ResourceManager.GetXsdSchema());
			schemas.Add(xsdSchemaCompletionData);
			XmlCompletionDataProvider provider = new XmlCompletionDataProvider(schemas, xsdSchemaCompletionData, String.Empty);
			
			string xml = GetSchema();
			int index = xml.IndexOf("type=\"text-type\"");
			index = xml.IndexOf("text-type", index);
			schemaComplexType = (XmlSchemaComplexType)XmlView.GetSchemaObjectSelected(xml, index, provider, SchemaCompletionData);
		}
예제 #23
0
        private void MarkAsMixed(ComplexType ct)
        {
            ComplexModel cm = ct.ContentModel as ComplexModel;

            if (cm != null)
            {
                cm.IsMixed = true;
            }
            else
            {
                ct.IsMixed = true;
            }
        }
예제 #24
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));
            }
        }
예제 #25
0
        protected override void Visit(XmlSchemaComplexType type)
        {
            if (type.QualifiedName.IsEmpty)
                base.Visit(type);
            else
            {
                if (!AddUsage(type))
                    return;

                PushNamedObject(type);
                base.Visit(type);
                PopNamedObject();
            }
        }
        private void setXsd(XmlSchemaComplexType xsCoxType) 
        {
            
            m_ClassGen.CName = xsCoxType.Name;

            if (xsCoxType.ContentModel == null)
            {
                if (xsCoxType.Particle is XmlSchemaGroupRef)
                {
                    // 만듬.
                }

                else if (xsCoxType.Particle is XmlSchemaGroupBase)
                {
                    XmlSchemaGroupBase xgb = xsCoxType.Particle as XmlSchemaGroupBase;
                    roopItem(xgb);
                }
            }

            else if (xsCoxType.ContentModel is XmlSchemaComplexContent)
            {
                XmlSchemaComplexContent xscc = xsCoxType.ContentModel as XmlSchemaComplexContent;

                if (xscc.Content is XmlSchemaComplexContentExtension)
                {
                    XmlSchemaComplexContentExtension xscc_Extension = xscc.Content as XmlSchemaComplexContentExtension;
                    m_ClassGen.BaseName = xscc_Extension.BaseTypeName.Name;

                    // 위에 (**) 코드랑 같이 가려고 했는데 XmlSchemaComplexType 하고 같은 인터페이스를 사용하지 않음. 아옭 헷갈리
                    if (xscc_Extension.Particle is XmlSchemaGroupRef)
                    {
                        // 만듬.
                    }

                    else if (xscc_Extension.Particle is XmlSchemaGroupBase)
                    {
                        XmlSchemaGroupBase xgb = xscc_Extension.Particle as XmlSchemaGroupBase;
                        roopItem(xgb);
                    }

                }
                else if (xscc.Content is XmlSchemaComplexContentRestriction)
                {
                    throw new NotImplementedException();
                }
                
            }
            
        }
예제 #27
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);
        }
예제 #28
0
 private static void AddElementAndType(XmlSchema schema, string baseXsdType, string ns)
 {
     XmlSchemaElement item = new XmlSchemaElement();
     item.Name = baseXsdType;
     item.SchemaTypeName = new XmlQualifiedName(baseXsdType, ns);
     schema.Items.Add(item);
     XmlSchemaComplexType type = new XmlSchemaComplexType();
     type.Name = baseXsdType;
     XmlSchemaSimpleContent content = new XmlSchemaSimpleContent();
     type.ContentModel = content;
     XmlSchemaSimpleContentExtension extension = new XmlSchemaSimpleContentExtension();
     extension.BaseTypeName = new XmlQualifiedName(baseXsdType, "http://www.w3.org/2001/XMLSchema");
     content.Content = extension;
     schema.Items.Add(type);
 }
        //const byte dupDeclMask = 0x08;

        static XmlSchemaComplexType() {
            anyTypeLax = CreateAnyType(XmlSchemaContentProcessing.Lax);
            anyTypeSkip = CreateAnyType(XmlSchemaContentProcessing.Skip);

            // Create xdt:untypedAny
            untypedAnyType = new XmlSchemaComplexType();
            untypedAnyType.SetQualifiedName(new XmlQualifiedName("untypedAny", XmlReservedNs.NsXQueryDataType));
            untypedAnyType.IsMixed = true;
            untypedAnyType.SetContentTypeParticle(anyTypeLax.ContentTypeParticle);
            untypedAnyType.SetContentType(XmlSchemaContentType.Mixed);

            untypedAnyType.ElementDecl = SchemaElementDecl.CreateAnyTypeElementDecl();
            untypedAnyType.ElementDecl.SchemaType = untypedAnyType;
            untypedAnyType.ElementDecl.ContentValidator = AnyTypeContentValidator;

        }
 private static void AddDefaultDatasetType(XmlSchemaSet schemas, string localName, string ns)
 {
     XmlSchemaComplexType item = new XmlSchemaComplexType {
         Name = localName,
         Particle = new XmlSchemaSequence()
     };
     XmlSchemaElement element = new XmlSchemaElement {
         RefName = new XmlQualifiedName("schema", "http://www.w3.org/2001/XMLSchema")
     };
     ((XmlSchemaSequence) item.Particle).Items.Add(element);
     XmlSchemaAny any = new XmlSchemaAny();
     ((XmlSchemaSequence) item.Particle).Items.Add(any);
     XmlSchema schema = SchemaHelper.GetSchema(ns, schemas);
     schema.Items.Add(item);
     schemas.Reprocess(schema);
 }
예제 #31
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);
        }
 private static void AddDefaultTypedDatasetType(XmlSchemaSet schemas, XmlSchema datasetSchema, string localName, string ns)
 {
     XmlSchemaComplexType item = new XmlSchemaComplexType {
         Name = localName,
         Particle = new XmlSchemaSequence()
     };
     XmlSchemaAny any = new XmlSchemaAny {
         Namespace = (datasetSchema.TargetNamespace == null) ? string.Empty : datasetSchema.TargetNamespace
     };
     ((XmlSchemaSequence) item.Particle).Items.Add(any);
     schemas.Add(datasetSchema);
     XmlSchema schema = SchemaHelper.GetSchema(ns, schemas);
     schema.Items.Add(item);
     schemas.Reprocess(datasetSchema);
     schemas.Reprocess(schema);
 }
예제 #33
0
        private SOMList GetAttributes(ComplexType ct)
        {
            if (ct.ContentModel == null)
            {
                return(ct.Attributes);
            }

            SimpleModel sc = ct.ContentModel as SimpleModel;

            if (sc != null)
            {
                SimpleExt sce = sc.Content as SimpleExt;
                if (sce != null)
                {
                    return(sce.Attributes);
                }
                SimpleRst scr = sc.Content as SimpleRst;
                if (scr != null)
                {
                    return(scr.Attributes);
                }
                else
                {
                    throw Error(sc, "Invalid simple content model.");
                }
            }
            ComplexModel cc = ct.ContentModel as ComplexModel;

            if (cc != null)
            {
                ComplexExt cce = cc.Content as ComplexExt;
                if (cce != null)
                {
                    return(cce.Attributes);
                }
                ComplexRst ccr = cc.Content as ComplexRst;
                if (ccr != null)
                {
                    return(ccr.Attributes);
                }
                else
                {
                    throw Error(cc, "Invalid simple content model.");
                }
            }
            throw Error(cc, "Invalid complexType. Should not happen.");
        }
예제 #34
0
        private void InferAsEmptyElement(Element el, string ns,
                                         bool isNew)
        {
            ComplexType ct = el.SchemaType as ComplexType;

            if (ct != null)
            {
                SimpleModel sm =
                    ct.ContentModel as SimpleModel;
                if (sm != null)
                {
                    ToEmptiableSimpleContent(sm, isNew);
                    return;
                }

                ComplexModel cm = ct.ContentModel
                                  as ComplexModel;
                if (cm != null)
                {
                    ToEmptiableComplexContent(cm, isNew);
                    return;
                }

                if (ct.Particle != null)
                {
                    ct.Particle.MinOccurs = 0;
                }
                return;
            }
            SimpleType st = el.SchemaType as SimpleType;

            if (st != null)
            {
                st = MakeBaseTypeAsEmptiable(st);
                switch (st.QualifiedName.Namespace)
                {
                case XmlSchema.Namespace:
                case XdtNamespace:
                    el.SchemaTypeName = st.QualifiedName;
                    break;

                default:
                    el.SchemaType = st;
                    break;
                }
            }
        }
        /// <summary>
        /// </summary>
        public override void GenerateSchemaTypeObjects(PropertyInfo property, XmlSchemaType type, int level)
        {
            var atts = GetAttributes<ConfigurationPropertyAttribute>(property);
            if (atts.Length == 0)
                return;

            XmlSchemaComplexType ct;
            if (Generator.ComplexMap.ContainsKey(property.PropertyType))
            {
                //already done the work
                ct = Generator.ComplexMap[property.PropertyType];
            }
            else
            {
                //  got to generate a new one
                ct = new XmlSchemaComplexType { Name = atts[0].Name + "CT" };
                ct.AddAnnotation(property, null);
                ct.CreateSchemaSequenceParticle();

                Generator.ComplexMap.Add(property.PropertyType, ct);
                Generator.Schema.Items.Add(ct);

                //  get all properties from the configuration object
                var propertyInfos = GetProperties<ConfigurationPropertyAttribute>(property.PropertyType);

                foreach (var pi in propertyInfos)
                {
                    var parser = TypeParserFactory.GetParser(Generator, pi);
                    parser.GenerateSchemaTypeObjects(pi, ct, level + 1);
                }
            }

            var element = new XmlSchemaElement
            {
                Name = atts[0].Name, // property.PropertyType.Name + "CT",
                MinOccurs = atts[0].IsRequired ? 1 : 0,
                SchemaTypeName = new XmlQualifiedName(XmlHelper.PrependNamespaceAlias(ct.Name))
            };
            var pct = (XmlSchemaComplexType) type;
            ((XmlSchemaGroupBase) pct.Particle).Items.Add(element);

            //  add the documentation
            element.AddAnnotation(property, atts[0]);
        }
예제 #36
0
        public XmlSchema GetDataSchemas(XmlSchema querySchema,IEnumerable<Registration> registrations)
        {
            var schema = new XmlSchema { TargetNamespace = RegistrationStorage.Dataspace };
            schema.Namespaces.Add("", RegistrationStorage.Dataspace);
            var guid = CreateGuidType();
            schema.Items.Add(guid);
            schema.Includes.Add(new XmlSchemaImport { Schema = querySchema, Namespace = querySchema.TargetNamespace });
            foreach (var registration in registrations)
            {
                var etype = new XmlSchemaComplexType
                {
                    Name = registration.ResourceName,
                    Annotation = new XmlSchemaAnnotation()
                };
                var doc = new XmlSchemaDocumentation { Markup = TextToNode(registration.ResourceType.FullName) };
                etype.Annotation.Items.Add(doc);
                etype.Block = XmlSchemaDerivationMethod.Extension;
                var idAttr = new XmlSchemaAttribute
                {
                    Name = "Id",
                    SchemaTypeName = new XmlQualifiedName(guid.Name, RegistrationStorage.Dataspace),
                    Use = XmlSchemaUse.Required
                };
                etype.Attributes.Add(idAttr);
                var noChildrenAttr = new XmlSchemaAttribute
                {
                    Name = RegistrationStorage.DefinitlyNoChildren,
                    SchemaType = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.Boolean),
                    Use = XmlSchemaUse.Optional
                };
                etype.Attributes.Add(noChildrenAttr);
                if (querySchema.Items.OfType<XmlSchemaAttributeGroup>().Any(k => k.Name == etype.Name))
                {

                    var group = new XmlSchemaAttributeGroupRef();
                    group.RefName = new XmlQualifiedName(etype.Name.Replace(" ", "_"), querySchema.TargetNamespace);
                    etype.Attributes.Add(group);

                }
                schema.Items.Add(etype);
            }

            return schema;
        }
예제 #37
0
        // It makes complexType not to have Simple content model.
        private void ToComplexContentType(ComplexType type)
        {
            SimpleModel sm = type.ContentModel as SimpleModel;

            if (sm == null)
            {
                return;
            }

            SOMList atts = GetAttributes(type);

            foreach (SOMObject o in atts)
            {
                type.Attributes.Add(o);
            }
            // FIXME: need to copy AnyAttribute.
            // (though not considered right now)
            type.ContentModel = null;
            type.IsMixed      = true;
        }
예제 #38
0
		public static void AssertCompiledComplexType (XmlSchemaComplexType cType,
			XmlQualifiedName name,
			int attributesCount, int attributeUsesCount,
			bool existsAny, Type contentModelType,
			bool hasContentTypeParticle,
			XmlSchemaContentType contentType)
		{
			Assert.IsNotNull (cType);
			Assert.AreEqual (name.Name, cType.Name);
			Assert.AreEqual (name, cType.QualifiedName);
			Assert.AreEqual (attributesCount, cType.Attributes.Count);
			Assert.AreEqual (attributeUsesCount, cType.AttributeUses.Count);
			Assert.IsTrue (existsAny == (cType.AttributeWildcard != null));
			if (contentModelType == null)
				Assert.IsNull (cType.ContentModel);
			else
				Assert.AreEqual (contentModelType, cType.ContentModel.GetType ());
			Assert.AreEqual (hasContentTypeParticle, cType.ContentTypeParticle != null);
			Assert.AreEqual (contentType, cType.ContentType);
		}
예제 #39
0
        /// <summary>
        /// Register a complex type in this schema object
        /// </summary>
        /// <param name="type">The complex type to register</param>
        protected void RegisterComplexType(System.Xml.Schema.XmlSchemaComplexType type)
        {
            if (types == null)
            {
                types = new List <XmlSchemaType>();
            }

            if (FindType(type.Name) != null)
            {
                return;                              // Already registered
            }
            // Now create a type
            XmlSchemaComplexType cplx = new XmlSchemaComplexType(this, null);

            cplx.Load(type);

            // Finally, add
            types.Add(cplx);
            typesDirty = true;
        }
예제 #40
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());
        }
예제 #41
0
        void AddExtensionAttributes(ClassInfo classInfo, XmlSchemaComplexType complex)
        {
            if (complex.ContentModel != null
                && complex.ContentModel.Content is XmlSchemaSimpleContentExtension)
            {
                var sce = complex.ContentModel.Content as XmlSchemaSimpleContentExtension;

                if (sce.Attributes.Count > 0)
                {
                    AddAttributes(classInfo, sce.Attributes);

                    var propInfo = new PropertyInfo(classInfo)
                    {
                        IsList = false,
                        XmlName = "Value",
                        XmlType = "Value",
                        IsElementValue = true
                    };
                    if (!classInfo.Elements.Contains(propInfo))
                        classInfo.Elements.Add(propInfo);
                }
            }
        }
예제 #42
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;
        }
예제 #43
0
        private static void ReadContent(XmlSchema schema, XmlSchemaReader reader, ValidationEventHandler h)
        {
            reader.MoveToElement();
            if (reader.LocalName != "schema" && reader.NamespaceURI != XmlSchema.Namespace && reader.NodeType != XmlNodeType.Element)
            {
                error(h, "UNREACHABLE CODE REACHED: Method: Schema.ReadContent, " + reader.LocalName + ", " + reader.NamespaceURI, null);
            }

            //(include | import | redefine | annotation)*,
            //((simpleType | complexType | group | attributeGroup | element | attribute | notation | annotation)*
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchema.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (level <= 1)
                {
                    if (reader.LocalName == "include")
                    {
                        XmlSchemaInclude include = XmlSchemaInclude.Read(reader, h);
                        if (include != null)
                        {
                            schema.includes.Add(include);
                        }
                        continue;
                    }
                    if (reader.LocalName == "import")
                    {
                        XmlSchemaImport import = XmlSchemaImport.Read(reader, h);
                        if (import != null)
                        {
                            schema.includes.Add(import);
                        }
                        continue;
                    }
                    if (reader.LocalName == "redefine")
                    {
                        XmlSchemaRedefine redefine = XmlSchemaRedefine.Read(reader, h);
                        if (redefine != null)
                        {
                            schema.includes.Add(redefine);
                        }
                        continue;
                    }
                    if (reader.LocalName == "annotation")
                    {
                        XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h);
                        if (annotation != null)
                        {
                            schema.items.Add(annotation);
                        }
                        continue;
                    }
                }
                if (level <= 2)
                {
                    level = 2;
                    if (reader.LocalName == "simpleType")
                    {
                        XmlSchemaSimpleType stype = XmlSchemaSimpleType.Read(reader, h);
                        if (stype != null)
                        {
                            schema.items.Add(stype);
                        }
                        continue;
                    }
                    if (reader.LocalName == "complexType")
                    {
                        XmlSchemaComplexType ctype = XmlSchemaComplexType.Read(reader, h);
                        if (ctype != null)
                        {
                            schema.items.Add(ctype);
                        }
                        continue;
                    }
                    if (reader.LocalName == "group")
                    {
                        XmlSchemaGroup group = XmlSchemaGroup.Read(reader, h);
                        if (group != null)
                        {
                            schema.items.Add(group);
                        }
                        continue;
                    }
                    if (reader.LocalName == "attributeGroup")
                    {
                        XmlSchemaAttributeGroup attributeGroup = XmlSchemaAttributeGroup.Read(reader, h);
                        if (attributeGroup != null)
                        {
                            schema.items.Add(attributeGroup);
                        }
                        continue;
                    }
                    if (reader.LocalName == "element")
                    {
                        XmlSchemaElement element = XmlSchemaElement.Read(reader, h);
                        if (element != null)
                        {
                            schema.items.Add(element);
                        }
                        continue;
                    }
                    if (reader.LocalName == "attribute")
                    {
                        XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader, h);
                        if (attr != null)
                        {
                            schema.items.Add(attr);
                        }
                        continue;
                    }
                    if (reader.LocalName == "notation")
                    {
                        XmlSchemaNotation notation = XmlSchemaNotation.Read(reader, h);
                        if (notation != null)
                        {
                            schema.items.Add(notation);
                        }
                        continue;
                    }
                    if (reader.LocalName == "annotation")
                    {
                        XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h);
                        if (annotation != null)
                        {
                            schema.items.Add(annotation);
                        }
                        continue;
                    }
                }
                reader.RaiseInvalidElementError();
            }
        }
 internal XmlSchemaObject Clone(XmlSchema parentSchema)
 {
     XmlSchemaComplexType type = (XmlSchemaComplexType) base.MemberwiseClone();
     if (type.ContentModel != null)
     {
         XmlSchemaSimpleContent contentModel = type.ContentModel as XmlSchemaSimpleContent;
         if (contentModel != null)
         {
             XmlSchemaSimpleContent content2 = (XmlSchemaSimpleContent) contentModel.Clone();
             XmlSchemaSimpleContentExtension content = contentModel.Content as XmlSchemaSimpleContentExtension;
             if (content != null)
             {
                 XmlSchemaSimpleContentExtension extension2 = (XmlSchemaSimpleContentExtension) content.Clone();
                 extension2.BaseTypeName = content.BaseTypeName.Clone();
                 extension2.SetAttributes(CloneAttributes(content.Attributes));
                 content2.Content = extension2;
             }
             else
             {
                 XmlSchemaSimpleContentRestriction restriction = (XmlSchemaSimpleContentRestriction) contentModel.Content;
                 XmlSchemaSimpleContentRestriction restriction2 = (XmlSchemaSimpleContentRestriction) restriction.Clone();
                 restriction2.BaseTypeName = restriction.BaseTypeName.Clone();
                 restriction2.SetAttributes(CloneAttributes(restriction.Attributes));
                 content2.Content = restriction2;
             }
             type.ContentModel = content2;
         }
         else
         {
             XmlSchemaComplexContent content3 = (XmlSchemaComplexContent) type.ContentModel;
             XmlSchemaComplexContent content4 = (XmlSchemaComplexContent) content3.Clone();
             XmlSchemaComplexContentExtension extension3 = content3.Content as XmlSchemaComplexContentExtension;
             if (extension3 != null)
             {
                 XmlSchemaComplexContentExtension extension4 = (XmlSchemaComplexContentExtension) extension3.Clone();
                 extension4.BaseTypeName = extension3.BaseTypeName.Clone();
                 extension4.SetAttributes(CloneAttributes(extension3.Attributes));
                 if (HasParticleRef(extension3.Particle, parentSchema))
                 {
                     extension4.Particle = CloneParticle(extension3.Particle, parentSchema);
                 }
                 content4.Content = extension4;
             }
             else
             {
                 XmlSchemaComplexContentRestriction restriction3 = content3.Content as XmlSchemaComplexContentRestriction;
                 XmlSchemaComplexContentRestriction restriction4 = (XmlSchemaComplexContentRestriction) restriction3.Clone();
                 restriction4.BaseTypeName = restriction3.BaseTypeName.Clone();
                 restriction4.SetAttributes(CloneAttributes(restriction3.Attributes));
                 if (HasParticleRef(restriction4.Particle, parentSchema))
                 {
                     restriction4.Particle = CloneParticle(restriction4.Particle, parentSchema);
                 }
                 content4.Content = restriction4;
             }
             type.ContentModel = content4;
         }
     }
     else
     {
         if (HasParticleRef(type.Particle, parentSchema))
         {
             type.Particle = CloneParticle(type.Particle, parentSchema);
         }
         type.SetAttributes(CloneAttributes(type.Attributes));
     }
     type.ClearCompiledState();
     return type;
 }
예제 #45
0
        private ComplexType ToComplexType(Element el)
        {
            QName         name = el.SchemaTypeName;
            XmlSchemaType type = el.SchemaType;

            // 1. element type is complex.
            ComplexType ct = type as ComplexType;

            if (ct != null)
            {
                return(ct);
            }

            // 2. reference to global complexType.
            XmlSchemaType globalType = schemas.GlobalTypes [name]
                                       as XmlSchemaType;

            ct = globalType as ComplexType;
            if (ct != null)
            {
                return(ct);
            }

            ct                = new ComplexType();
            el.SchemaType     = ct;
            el.SchemaTypeName = QName.Empty;

            // 3. base type name is xs:anyType or no specification.
            // <xs:complexType />
            if (name == QNameAnyType)
            {
                return(ct);
            }
            else if (type == null && name == QName.Empty)
            {
                return(ct);
            }

            SimpleModel sc = new SimpleModel();

            ct.ContentModel = sc;

            // 4. type is simpleType
            //    -> extension of existing simple type.
            SimpleType st = type as SimpleType;

            if (st != null)
            {
                SimpleRst scr = new SimpleRst();
                scr.BaseType = st;
                sc.Content   = scr;
                return(ct);
            }

            SimpleExt sce = new SimpleExt();

            sc.Content = sce;

            // 5. type name points to primitive type
            //    -> simple extension of a primitive type
            st = XmlSchemaType.GetBuiltInSimpleType(name);
            if (st != null)
            {
                sce.BaseTypeName = name;
                return(ct);
            }

            // 6. type name points to global simpleType.
            st = globalType as SimpleType;
            if (st != null)
            {
                sce.BaseTypeName = name;
                return(ct);
            }

            throw Error(el, "Unexpected schema component that contains simpleTypeName that could not be resolved.");
        }
예제 #46
0
        private void InferAttributes(Element el, string ns, bool isNew)
        {
            // Now this element is going to have complexType.
            // It currently not, then we have to replace it.
            ComplexType ct      = null;
            SOMList     attList = null;
            Hashtable   table   = null;

            do
            {
                switch (source.NamespaceURI)
                {
                case NamespaceXml:
                    if (schemas.Schemas(
                            NamespaceXml).Count == 0)
                    {
                        IncludeXmlAttributes();
                    }
                    break;

                case XmlSchema.InstanceNamespace:
                    if (source.LocalName == "nil")
                    {
                        el.IsNillable = true;
                    }
                    // all other xsi:* atts are ignored
                    continue;

                case NamespaceXmlns:
                    continue;
                }
                if (ct == null)
                {
                    ct      = ToComplexType(el);
                    attList = GetAttributes(ct);
                    table   = CollectAttrTable(attList);
                }
                QName attrName = new QName(
                    source.LocalName, source.NamespaceURI);
                Attr attr = table [attrName] as Attr;
                if (attr == null)
                {
                    attList.Add(InferNewAttribute(
                                    attrName, isNew, ns));
                }
                else
                {
                    table.Remove(attrName);
                    if (attr.RefName != null &&
                        attr.RefName != QName.Empty)
                    {
                        continue;                         // just a reference
                    }
                    InferMergedAttribute(attr);
                }
            } while (source.MoveToNextAttribute());

            // mark all attr definitions that did not appear
            // as optional.
            if (table != null)
            {
                foreach (Attr attr in table.Values)
                {
                    attr.Use = Use.Optional;
                }
            }
        }
예제 #47
0
        void DoCompile(ValidationEventHandler handler, Hashtable handledUris, XmlSchemaSet col, XmlResolver resolver)
        {
            SetParent();
            CompilationId = col.CompilationId;
            schemas       = col;
            if (!schemas.Contains(this))              // e.g. xs:import
            {
                schemas.Add(this);
            }

            attributeGroups.Clear();
            attributes.Clear();
            elements.Clear();
            groups.Clear();
            notations.Clear();
            schemaTypes.Clear();

            //1. Union and List are not allowed in block default
            if (BlockDefault != XmlSchemaDerivationMethod.All)
            {
                if ((BlockDefault & XmlSchemaDerivationMethod.List) != 0)
                {
                    error(handler, "list is not allowed in blockDefault attribute");
                }
                if ((BlockDefault & XmlSchemaDerivationMethod.Union) != 0)
                {
                    error(handler, "union is not allowed in blockDefault attribute");
                }
            }

            //2. Substitution is not allowed in finaldefault.
            if (FinalDefault != XmlSchemaDerivationMethod.All)
            {
                if ((FinalDefault & XmlSchemaDerivationMethod.Substitution) != 0)
                {
                    error(handler, "substitution is not allowed in finalDefault attribute");
                }
            }

            //3. id must be of type ID
            XmlSchemaUtil.CompileID(Id, this, col.IDCollection, handler);

            //4. targetNamespace should be of type anyURI or absent
            if (TargetNamespace != null)
            {
                if (TargetNamespace.Length == 0)
                {
                    error(handler, "The targetNamespace attribute cannot have have empty string as its value.");
                }

                if (!XmlSchemaUtil.CheckAnyUri(TargetNamespace))
                {
                    error(handler, TargetNamespace + " is not a valid value for targetNamespace attribute of schema");
                }
            }

            //5. version should be of type normalizedString
            if (!XmlSchemaUtil.CheckNormalizedString(Version))
            {
                error(handler, Version + "is not a valid value for version attribute of schema");
            }

            // Compile the content of this schema

            compilationItems = new XmlSchemaObjectCollection();
            for (int i = 0; i < Items.Count; i++)
            {
                compilationItems.Add(Items [i]);
            }

            // First, we run into inclusion schemas to collect
            // compilation target items into compiledItems.
            for (int i = 0; i < Includes.Count; i++)
            {
                XmlSchemaExternal ext = Includes [i] as XmlSchemaExternal;
                if (ext == null)
                {
                    error(handler, String.Format("Object of Type {0} is not valid in Includes Property of XmlSchema", Includes [i].GetType().Name));
                    continue;
                }

                if (ext.SchemaLocation == null)
                {
                    continue;
                }

                Stream stream = null;
                string url    = null;
                if (resolver != null)
                {
                    url = GetResolvedUri(resolver, ext.SchemaLocation);
                    if (handledUris.Contains(url))
                    {
                        // This schema is already handled, so simply skip (otherwise, duplicate definition errrors occur.
                        continue;
                    }
                    handledUris.Add(url, url);
                    try {
                        stream = resolver.GetEntity(new Uri(url), null, typeof(Stream)) as Stream;
                    } catch (Exception) {
                        // LAMESPEC: This is not good way to handle errors, but since we cannot know what kind of XmlResolver will come, so there are no mean to avoid this ugly catch.
                        warn(handler, "Could not resolve schema location URI: " + url);
                        stream = null;
                    }
                }

                // Process redefinition children in advance.
                XmlSchemaRedefine redefine = Includes [i] as XmlSchemaRedefine;
                if (redefine != null)
                {
                    for (int j = 0; j < redefine.Items.Count; j++)
                    {
                        XmlSchemaObject redefinedObj = redefine.Items [j];
                        redefinedObj.isRedefinedComponent = true;
                        redefinedObj.isRedefineChild      = true;
                        if (redefinedObj is XmlSchemaType ||
                            redefinedObj is XmlSchemaGroup ||
                            redefinedObj is XmlSchemaAttributeGroup)
                        {
                            compilationItems.Add(redefinedObj);
                        }
                        else
                        {
                            error(handler, "Redefinition is only allowed to simpleType, complexType, group and attributeGroup.");
                        }
                    }
                }

                XmlSchema includedSchema = null;
                if (stream == null)
                {
                    // It is missing schema components.
                    missedSubComponents = true;
                    continue;
                }
                else
                {
                    XmlTextReader xtr = null;
                    try {
                        xtr            = new XmlTextReader(url, stream, nameTable);
                        includedSchema = XmlSchema.Read(xtr, handler);
                    } finally {
                        if (xtr != null)
                        {
                            xtr.Close();
                        }
                    }
                    includedSchema.schemas = schemas;
                }
                includedSchema.SetParent();
                ext.Schema = includedSchema;

                // Set - actual - target namespace for the included schema * before compilation*.
                XmlSchemaImport import = ext as XmlSchemaImport;
                if (import != null)
                {
                    if (TargetNamespace == includedSchema.TargetNamespace)
                    {
                        error(handler, "Target namespace must be different from that of included schema.");
                        continue;
                    }
                    else if (includedSchema.TargetNamespace != import.Namespace)
                    {
                        error(handler, "Attribute namespace and its importing schema's target namespace must be the same.");
                        continue;
                    }
                }
                else
                {
                    if (TargetNamespace == null &&
                        includedSchema.TargetNamespace != null)
                    {
                        error(handler, "Target namespace is required to include a schema which has its own target namespace");
                        continue;
                    }
                    else if (TargetNamespace != null &&
                             includedSchema.TargetNamespace == null)
                    {
                        includedSchema.TargetNamespace = TargetNamespace;
                    }
                }

                // Do not compile included schema here.

                AddExternalComponentsTo(includedSchema, compilationItems);
            }

            // Compilation phase.
            // At least each Compile() must give unique (qualified) name for each component.
            // It also checks self-resolvable properties correctness.
            // Post compilation schema information contribution is not done here.
            // It should be done by Validate().
            for (int i = 0; i < compilationItems.Count; i++)
            {
                XmlSchemaObject obj = compilationItems [i];
                if (obj is XmlSchemaAnnotation)
                {
                    int numerr = ((XmlSchemaAnnotation)obj).Compile(handler, this);
                    errorCount += numerr;
                }
                else if (obj is XmlSchemaAttribute)
                {
                    XmlSchemaAttribute attr = (XmlSchemaAttribute)obj;
                    int numerr = attr.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(Attributes, attr, attr.QualifiedName, handler);
                    }
                }
                else if (obj is XmlSchemaAttributeGroup)
                {
                    XmlSchemaAttributeGroup attrgrp = (XmlSchemaAttributeGroup)obj;
                    int numerr = attrgrp.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            AttributeGroups,
                            attrgrp,
                            attrgrp.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaComplexType)
                {
                    XmlSchemaComplexType ctype = (XmlSchemaComplexType)obj;
                    int numerr = ctype.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            schemaTypes,
                            ctype,
                            ctype.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaSimpleType)
                {
                    XmlSchemaSimpleType stype = (XmlSchemaSimpleType)obj;
                    stype.islocal = false;                     //This simple type is toplevel
                    int numerr = stype.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            SchemaTypes,
                            stype,
                            stype.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaElement)
                {
                    XmlSchemaElement elem = (XmlSchemaElement)obj;
                    elem.parentIsSchema = true;
                    int numerr = elem.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            Elements,
                            elem,
                            elem.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaGroup)
                {
                    XmlSchemaGroup grp    = (XmlSchemaGroup)obj;
                    int            numerr = grp.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            Groups,
                            grp,
                            grp.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaNotation)
                {
                    XmlSchemaNotation ntn = (XmlSchemaNotation)obj;
                    int numerr            = ntn.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            Notations,
                            ntn,
                            ntn.QualifiedName,
                            handler);
                    }
                }
                else
                {
                    ValidationHandler.RaiseValidationEvent(
                        handler,
                        null,
                        String.Format("Object of Type {0} is not valid in Item Property of Schema", obj.GetType().Name),
                        null,
                        this,
                        null,
                        XmlSeverityType.Error);
                }
            }
        }
        internal static XmlSchemaRedefine Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaRedefine xmlSchemaRedefine = new XmlSchemaRedefine();

            reader.MoveToElement();
            if (reader.NamespaceURI != "http://www.w3.org/2001/XMLSchema" || reader.LocalName != "redefine")
            {
                XmlSchemaObject.error(h, "Should not happen :1: XmlSchemaRedefine.Read, name=" + reader.Name, null);
                reader.Skip();
                return(null);
            }
            xmlSchemaRedefine.LineNumber   = reader.LineNumber;
            xmlSchemaRedefine.LinePosition = reader.LinePosition;
            xmlSchemaRedefine.SourceUri    = reader.BaseURI;
            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    xmlSchemaRedefine.Id = reader.Value;
                }
                else if (reader.Name == "schemaLocation")
                {
                    xmlSchemaRedefine.SchemaLocation = reader.Value;
                }
                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 redefine", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, xmlSchemaRedefine);
                }
            }
            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(xmlSchemaRedefine);
            }
            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != "redefine")
                    {
                        XmlSchemaObject.error(h, "Should not happen :2: XmlSchemaRedefine.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (reader.LocalName == "annotation")
                {
                    XmlSchemaAnnotation xmlSchemaAnnotation = XmlSchemaAnnotation.Read(reader, h);
                    if (xmlSchemaAnnotation != null)
                    {
                        xmlSchemaRedefine.items.Add(xmlSchemaAnnotation);
                    }
                }
                else if (reader.LocalName == "simpleType")
                {
                    XmlSchemaSimpleType xmlSchemaSimpleType = XmlSchemaSimpleType.Read(reader, h);
                    if (xmlSchemaSimpleType != null)
                    {
                        xmlSchemaRedefine.items.Add(xmlSchemaSimpleType);
                    }
                }
                else if (reader.LocalName == "complexType")
                {
                    XmlSchemaComplexType xmlSchemaComplexType = XmlSchemaComplexType.Read(reader, h);
                    if (xmlSchemaComplexType != null)
                    {
                        xmlSchemaRedefine.items.Add(xmlSchemaComplexType);
                    }
                }
                else if (reader.LocalName == "group")
                {
                    XmlSchemaGroup xmlSchemaGroup = XmlSchemaGroup.Read(reader, h);
                    if (xmlSchemaGroup != null)
                    {
                        xmlSchemaRedefine.items.Add(xmlSchemaGroup);
                    }
                }
                else if (reader.LocalName == "attributeGroup")
                {
                    XmlSchemaAttributeGroup xmlSchemaAttributeGroup = XmlSchemaAttributeGroup.Read(reader, h);
                    if (xmlSchemaAttributeGroup != null)
                    {
                        xmlSchemaRedefine.items.Add(xmlSchemaAttributeGroup);
                    }
                }
                else
                {
                    reader.RaiseInvalidElementError();
                }
            }
            return(xmlSchemaRedefine);
        }
예제 #49
0
        private void InferTextContent(Element el, bool isNew)
        {
            string value = source.ReadString();

            if (el.SchemaType == null)
            {
                if (el.SchemaTypeName == QName.Empty)
                {
                    // no type information -> infer type
                    if (isNew)
                    {
                        el.SchemaTypeName =
                            InferSimpleType(
                                value);
                    }
                    else
                    {
                        el.SchemaTypeName =
                            QNameString;
                    }
                    return;
                }
                switch (el.SchemaTypeName.Namespace)
                {
                case XmlSchema.Namespace:
                case XdtNamespace:
                    // existing primitive type
                    el.SchemaTypeName = InferMergedType(
                        value, el.SchemaTypeName);
                    break;

                default:
                    ComplexType ct = schemas.GlobalTypes [
                        el.SchemaTypeName]
                                     as ComplexType;
                    // If it is complex, then just set
                    // mixed='true' (type cannot be set.)
                    // If it is simple, then we cannot
                    // make sure that string value is
                    // valid. So just set as xs:string.
                    if (ct != null)
                    {
                        MarkAsMixed(ct);
                    }
                    else
                    {
                        el.SchemaTypeName = QNameString;
                    }
                    break;
                }
                return;
            }
            // simpleType
            SimpleType st = el.SchemaType as SimpleType;

            if (st != null)
            {
                // If simple, then (described above)
                el.SchemaType     = null;
                el.SchemaTypeName = QNameString;
                return;
            }

            // complexType
            ComplexType ect = el.SchemaType as ComplexType;

            SimpleModel sm = ect.ContentModel as SimpleModel;

            if (sm == null)
            {
                // - ComplexContent
                MarkAsMixed(ect);
                return;
            }

            // - SimpleContent
            SimpleExt se = sm.Content as SimpleExt;

            if (se != null)
            {
                se.BaseTypeName = InferMergedType(value,
                                                  se.BaseTypeName);
            }
            SimpleRst sr = sm.Content as SimpleRst;

            if (sr != null)
            {
                sr.BaseTypeName = InferMergedType(value,
                                                  sr.BaseTypeName);
                sr.BaseType = null;
            }
        }
예제 #50
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);
                }
            }
        }
예제 #51
0
        internal XmlSchemaObject Clone(XmlSchema?parentSchema)
        {
            XmlSchemaComplexType complexType = (XmlSchemaComplexType)MemberwiseClone();

            //Deep clone the QNames as these will be updated on chameleon includes
            if (complexType.ContentModel != null)
            { //simpleContent or complexContent
                XmlSchemaSimpleContent?simpleContent = complexType.ContentModel as XmlSchemaSimpleContent;
                if (simpleContent != null)
                {
                    XmlSchemaSimpleContent newSimpleContent = (XmlSchemaSimpleContent)simpleContent.Clone();

                    XmlSchemaSimpleContentExtension?simpleExt = simpleContent.Content as XmlSchemaSimpleContentExtension;
                    if (simpleExt != null)
                    {
                        XmlSchemaSimpleContentExtension newSimpleExt = (XmlSchemaSimpleContentExtension)simpleExt.Clone();
                        newSimpleExt.BaseTypeName = simpleExt.BaseTypeName.Clone();
                        newSimpleExt.SetAttributes(CloneAttributes(simpleExt.Attributes));
                        newSimpleContent.Content = newSimpleExt;
                    }
                    else
                    { //simpleContent.Content is XmlSchemaSimpleContentRestriction
                        XmlSchemaSimpleContentRestriction simpleRest    = (XmlSchemaSimpleContentRestriction)simpleContent.Content !;
                        XmlSchemaSimpleContentRestriction newSimpleRest = (XmlSchemaSimpleContentRestriction)simpleRest.Clone();
                        newSimpleRest.BaseTypeName = simpleRest.BaseTypeName.Clone();
                        newSimpleRest.SetAttributes(CloneAttributes(simpleRest.Attributes));
                        newSimpleContent.Content = newSimpleRest;
                    }

                    complexType.ContentModel = newSimpleContent;
                }
                else
                { // complexType.ContentModel is XmlSchemaComplexContent
                    XmlSchemaComplexContent complexContent    = (XmlSchemaComplexContent)complexType.ContentModel;
                    XmlSchemaComplexContent newComplexContent = (XmlSchemaComplexContent)complexContent.Clone();

                    XmlSchemaComplexContentExtension?complexExt = complexContent.Content as XmlSchemaComplexContentExtension;
                    if (complexExt != null)
                    {
                        XmlSchemaComplexContentExtension newComplexExt = (XmlSchemaComplexContentExtension)complexExt.Clone();
                        newComplexExt.BaseTypeName = complexExt.BaseTypeName.Clone();
                        newComplexExt.SetAttributes(CloneAttributes(complexExt.Attributes));
                        if (HasParticleRef(complexExt.Particle, parentSchema))
                        {
                            newComplexExt.Particle = CloneParticle(complexExt.Particle, parentSchema);
                        }
                        newComplexContent.Content = newComplexExt;
                    }
                    else
                    { // complexContent.Content is XmlSchemaComplexContentRestriction
                        XmlSchemaComplexContentRestriction complexRest    = (complexContent.Content as XmlSchemaComplexContentRestriction) !;
                        XmlSchemaComplexContentRestriction newComplexRest = (XmlSchemaComplexContentRestriction)complexRest.Clone();
                        newComplexRest.BaseTypeName = complexRest.BaseTypeName.Clone();
                        newComplexRest.SetAttributes(CloneAttributes(complexRest.Attributes));
                        if (HasParticleRef(newComplexRest.Particle, parentSchema))
                        {
                            newComplexRest.Particle = CloneParticle(newComplexRest.Particle, parentSchema);
                        }

                        newComplexContent.Content = newComplexRest;
                    }

                    complexType.ContentModel = newComplexContent;
                }
            }
            else
            { //equals XmlSchemaComplexContent with baseType is anyType
                if (HasParticleRef(complexType.Particle, parentSchema))
                {
                    complexType.Particle = CloneParticle(complexType.Particle, parentSchema);
                }
                complexType.SetAttributes(CloneAttributes(complexType.Attributes));
            }
            complexType.ClearCompiledState();
            return(complexType);
        }
//<redefine
//  id = ID
//  schemaLocation = anyURI
//  {any attributes with non-schema namespace . . .}>
//  Content: (annotation | (simpleType | complexType | group | attributeGroup))*
//</redefine>
        internal static XmlSchemaRedefine Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaRedefine redefine = new XmlSchemaRedefine();

            reader.MoveToElement();

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

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

            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    redefine.Id = reader.Value;
                }
                else if (reader.Name == "schemaLocation")
                {
                    redefine.SchemaLocation = reader.Value;
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for redefine", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, redefine);
                }
            }

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

            //(annotation | (simpleType | complexType | group | attributeGroup))*
            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaRedefine.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (reader.LocalName == "annotation")
                {
                    XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h);
                    if (annotation != null)
                    {
                        redefine.items.Add(annotation);
                    }
                    continue;
                }
                if (reader.LocalName == "simpleType")
                {
                    XmlSchemaSimpleType simpleType = XmlSchemaSimpleType.Read(reader, h);
                    if (simpleType != null)
                    {
                        redefine.items.Add(simpleType);
                    }
                    continue;
                }
                if (reader.LocalName == "complexType")
                {
                    XmlSchemaComplexType complexType = XmlSchemaComplexType.Read(reader, h);
                    if (complexType != null)
                    {
                        redefine.items.Add(complexType);
                    }
                    continue;
                }
                if (reader.LocalName == "group")
                {
                    XmlSchemaGroup group = XmlSchemaGroup.Read(reader, h);
                    if (group != null)
                    {
                        redefine.items.Add(group);
                    }
                    continue;
                }
                if (reader.LocalName == "attributeGroup")
                {
                    XmlSchemaAttributeGroup attributeGroup = XmlSchemaAttributeGroup.Read(reader, h);
                    if (attributeGroup != null)
                    {
                        redefine.items.Add(attributeGroup);
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(redefine);
        }
예제 #53
0
        void ReadServiceDescription()
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                XmlTextReader           reader  = new XmlTextReader(comboBox1.Text);
                Desc.ServiceDescription service =
                    Desc.ServiceDescription.Read(reader);

                //WSDLParser.WSDLParser wsdl = new EIBFormDesigner.WSDLParser.WSDLParser(service);

                comboNamespace.Items.Add(service.TargetNamespace);
                foreach (Desc.PortType pt in service.PortTypes)
                {
                    //Console.WriteLine("PortType {0}", pt.Name);

                    foreach (Desc.Operation op in pt.Operations)
                    {
                        //Console.WriteLine("\tOperation: {0}", op.Name);
                        comboBox2.Items.Add(op.Name);
                        //service.Services[service.Name].Ports[pt.Name]
                        Desc.Types types = service.Types;
                        System.Xml.Schema.XmlSchema xmlSchema = types.Schemas[0];

                        //string typeName = service.Messages[op.Messages.Input.Message.Name].FindPartByName(op.Messages.Input.Message.Name).Type.Name;
                        System.Web.Services.Description.MessagePart msgPart = service.Messages[op.Messages.Input.Message.Name].Parts["parameters"];
                        string paramElementName = null;
                        if (msgPart != null)
                        {
                            paramElementName = msgPart.Element.Name;
                            parameterMappings.Add(paramElementName, new Dictionary <string, string>());
                        }
                        foreach (object obj in xmlSchema.Items)
                        {
                            System.Xml.Schema.XmlSchemaElement sElement = obj as System.Xml.Schema.XmlSchemaElement;
                            if (sElement != null && sElement.Name == paramElementName)
                            {
                                if (sElement.SchemaType != null && sElement.SchemaType.GetType() == typeof(System.Xml.Schema.XmlSchemaComplexType))
                                {
                                    System.Xml.Schema.XmlSchemaComplexType xComplexType = sElement.SchemaType as System.Xml.Schema.XmlSchemaComplexType;
                                    TraverseParticle(xComplexType.Particle, paramElementName);
                                }
                                break;
                            }

                            /*if (obj is System.Xml.Schema.XmlSchemaComplexType)
                             * {
                             *  System.Xml.Schema.XmlSchemaComplexType xComplexType = obj as System.Xml.Schema.XmlSchemaComplexType;
                             *  if (xComplexType.Name == )
                             *  {
                             *      MessageBox.Show(xComplexType.Name + " : " + typeName);
                             *      TraverseParticle(xComplexType.ContentTypeParticle);
                             *
                             *  }
                             * }*/
                        }
                    }
                }


                //wsdl.WSDLParser parser = new wsdl.WSDLParser(service);

                //this.tvwService.Nodes.Add(parser.ServiceNode);
                //this.cboURL.Items.Add(cboURL.Text);
                //http://soap.amazon.com/schemas2/AmazonWebServices.wsdl
                //http://glkev.webs.innerhost.com/glkev_ws/weatherfetcher.asmx?wsdl
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message.ToString());
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
 private void PreprocessComplexType(XmlSchemaComplexType complexType, bool local)
 {
     if (local)
     {
         if (complexType.Name != null)
         {
             base.SendValidationEvent("Sch_ForbiddenAttribute", "name", complexType);
         }
     }
     else
     {
         if (complexType.Name != null)
         {
             this.ValidateNameAttribute(complexType);
             complexType.SetQualifiedName(new XmlQualifiedName(complexType.Name, this.targetNamespace));
         }
         else
         {
             base.SendValidationEvent("Sch_MissRequiredAttribute", "name", complexType);
         }
         if (complexType.Block == XmlSchemaDerivationMethod.All)
         {
             complexType.SetBlockResolved(XmlSchemaDerivationMethod.All);
         }
         else if (complexType.Block == XmlSchemaDerivationMethod.None)
         {
             complexType.SetBlockResolved(this.blockDefault & (XmlSchemaDerivationMethod.Restriction | XmlSchemaDerivationMethod.Extension));
         }
         else
         {
             if ((complexType.Block & ~(XmlSchemaDerivationMethod.Restriction | XmlSchemaDerivationMethod.Extension)) != XmlSchemaDerivationMethod.Empty)
             {
                 base.SendValidationEvent("Sch_InvalidComplexTypeBlockValue", complexType);
             }
             complexType.SetBlockResolved(complexType.Block & (XmlSchemaDerivationMethod.Restriction | XmlSchemaDerivationMethod.Extension));
         }
         if (complexType.Final == XmlSchemaDerivationMethod.All)
         {
             complexType.SetFinalResolved(XmlSchemaDerivationMethod.All);
         }
         else if (complexType.Final == XmlSchemaDerivationMethod.None)
         {
             if (this.finalDefault == XmlSchemaDerivationMethod.All)
             {
                 complexType.SetFinalResolved(XmlSchemaDerivationMethod.All);
             }
             else
             {
                 complexType.SetFinalResolved(this.finalDefault & (XmlSchemaDerivationMethod.Restriction | XmlSchemaDerivationMethod.Extension));
             }
         }
         else
         {
             if ((complexType.Final & ~(XmlSchemaDerivationMethod.Restriction | XmlSchemaDerivationMethod.Extension)) != XmlSchemaDerivationMethod.Empty)
             {
                 base.SendValidationEvent("Sch_InvalidComplexTypeFinalValue", complexType);
             }
             complexType.SetFinalResolved(complexType.Final & (XmlSchemaDerivationMethod.Restriction | XmlSchemaDerivationMethod.Extension));
         }
     }
     if (complexType.ContentModel != null)
     {
         this.SetParent(complexType.ContentModel, complexType);
         this.PreprocessAnnotation(complexType.ContentModel);
         if (complexType.Particle == null)
         {
             XmlSchemaObjectCollection attributes = complexType.Attributes;
         }
         if (complexType.ContentModel is XmlSchemaSimpleContent)
         {
             XmlSchemaSimpleContent contentModel = (XmlSchemaSimpleContent) complexType.ContentModel;
             if (contentModel.Content == null)
             {
                 if (complexType.QualifiedName == XmlQualifiedName.Empty)
                 {
                     base.SendValidationEvent("Sch_NoRestOrExt", complexType);
                 }
                 else
                 {
                     base.SendValidationEvent("Sch_NoRestOrExtQName", complexType.QualifiedName.Name, complexType.QualifiedName.Namespace, complexType);
                 }
             }
             else
             {
                 this.SetParent(contentModel.Content, contentModel);
                 this.PreprocessAnnotation(contentModel.Content);
                 if (contentModel.Content is XmlSchemaSimpleContentExtension)
                 {
                     XmlSchemaSimpleContentExtension content = (XmlSchemaSimpleContentExtension) contentModel.Content;
                     if (content.BaseTypeName.IsEmpty)
                     {
                         base.SendValidationEvent("Sch_MissAttribute", "base", content);
                     }
                     else
                     {
                         this.ValidateQNameAttribute(content, "base", content.BaseTypeName);
                     }
                     this.PreprocessAttributes(content.Attributes, content.AnyAttribute, content);
                     this.ValidateIdAttribute(content);
                 }
                 else
                 {
                     XmlSchemaSimpleContentRestriction source = (XmlSchemaSimpleContentRestriction) contentModel.Content;
                     if (source.BaseTypeName.IsEmpty)
                     {
                         base.SendValidationEvent("Sch_MissAttribute", "base", source);
                     }
                     else
                     {
                         this.ValidateQNameAttribute(source, "base", source.BaseTypeName);
                     }
                     if (source.BaseType != null)
                     {
                         this.SetParent(source.BaseType, source);
                         this.PreprocessSimpleType(source.BaseType, true);
                     }
                     this.PreprocessAttributes(source.Attributes, source.AnyAttribute, source);
                     this.ValidateIdAttribute(source);
                 }
             }
             this.ValidateIdAttribute(contentModel);
         }
         else
         {
             XmlSchemaComplexContent parent = (XmlSchemaComplexContent) complexType.ContentModel;
             if (parent.Content == null)
             {
                 if (complexType.QualifiedName == XmlQualifiedName.Empty)
                 {
                     base.SendValidationEvent("Sch_NoRestOrExt", complexType);
                 }
                 else
                 {
                     base.SendValidationEvent("Sch_NoRestOrExtQName", complexType.QualifiedName.Name, complexType.QualifiedName.Namespace, complexType);
                 }
             }
             else
             {
                 if (!parent.HasMixedAttribute && complexType.IsMixed)
                 {
                     parent.IsMixed = true;
                 }
                 this.SetParent(parent.Content, parent);
                 this.PreprocessAnnotation(parent.Content);
                 if (parent.Content is XmlSchemaComplexContentExtension)
                 {
                     XmlSchemaComplexContentExtension extension2 = (XmlSchemaComplexContentExtension) parent.Content;
                     if (extension2.BaseTypeName.IsEmpty)
                     {
                         base.SendValidationEvent("Sch_MissAttribute", "base", extension2);
                     }
                     else
                     {
                         this.ValidateQNameAttribute(extension2, "base", extension2.BaseTypeName);
                     }
                     if (extension2.Particle != null)
                     {
                         this.SetParent(extension2.Particle, extension2);
                         this.PreprocessParticle(extension2.Particle);
                     }
                     this.PreprocessAttributes(extension2.Attributes, extension2.AnyAttribute, extension2);
                     this.ValidateIdAttribute(extension2);
                 }
                 else
                 {
                     XmlSchemaComplexContentRestriction restriction2 = (XmlSchemaComplexContentRestriction) parent.Content;
                     if (restriction2.BaseTypeName.IsEmpty)
                     {
                         base.SendValidationEvent("Sch_MissAttribute", "base", restriction2);
                     }
                     else
                     {
                         this.ValidateQNameAttribute(restriction2, "base", restriction2.BaseTypeName);
                     }
                     if (restriction2.Particle != null)
                     {
                         this.SetParent(restriction2.Particle, restriction2);
                         this.PreprocessParticle(restriction2.Particle);
                     }
                     this.PreprocessAttributes(restriction2.Attributes, restriction2.AnyAttribute, restriction2);
                     this.ValidateIdAttribute(restriction2);
                 }
                 this.ValidateIdAttribute(parent);
             }
         }
     }
     else
     {
         if (complexType.Particle != null)
         {
             this.SetParent(complexType.Particle, complexType);
             this.PreprocessParticle(complexType.Particle);
         }
         this.PreprocessAttributes(complexType.Attributes, complexType.AnyAttribute, complexType);
     }
     this.ValidateIdAttribute(complexType);
 }
예제 #55
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;
        }
예제 #56
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);
        }
 private void CheckRefinedComplexType(XmlSchemaComplexType ctype)
 {
     if (ctype.ContentModel != null)
     {
         XmlQualifiedName baseTypeName;
         if (ctype.ContentModel is XmlSchemaComplexContent)
         {
             XmlSchemaComplexContent contentModel = (XmlSchemaComplexContent) ctype.ContentModel;
             if (contentModel.Content is XmlSchemaComplexContentRestriction)
             {
                 baseTypeName = ((XmlSchemaComplexContentRestriction) contentModel.Content).BaseTypeName;
             }
             else
             {
                 baseTypeName = ((XmlSchemaComplexContentExtension) contentModel.Content).BaseTypeName;
             }
         }
         else
         {
             XmlSchemaSimpleContent content2 = (XmlSchemaSimpleContent) ctype.ContentModel;
             if (content2.Content is XmlSchemaSimpleContentRestriction)
             {
                 baseTypeName = ((XmlSchemaSimpleContentRestriction) content2.Content).BaseTypeName;
             }
             else
             {
                 baseTypeName = ((XmlSchemaSimpleContentExtension) content2.Content).BaseTypeName;
             }
         }
         if (baseTypeName == ctype.QualifiedName)
         {
             return;
         }
     }
     base.SendValidationEvent("Sch_InvalidTypeRedefine", ctype);
 }
예제 #58
0
        void DoCompile(ValidationEventHandler handler, List <CompiledSchemaMemo> handledUris, XmlSchemaSet col, XmlResolver resolver)
        {
            SetParent();
            CompilationId = col.CompilationId;
            schemas       = col;
            if (!schemas.Contains(this))              // e.g. xs:import
            {
                schemas.Add(this);
            }

            attributeGroups.Clear();
            attributes.Clear();
            elements.Clear();
            groups.Clear();
            notations.Clear();
            schemaTypes.Clear();
            named_identities.Clear();
            ids.Clear();
            compilationItems.Clear();

            //1. Union and List are not allowed in block default
            if (BlockDefault != XmlSchemaDerivationMethod.All)
            {
                if ((BlockDefault & XmlSchemaDerivationMethod.List) != 0)
                {
                    error(handler, "list is not allowed in blockDefault attribute");
                }
                if ((BlockDefault & XmlSchemaDerivationMethod.Union) != 0)
                {
                    error(handler, "union is not allowed in blockDefault attribute");
                }
            }

            //2. Substitution is not allowed in finaldefault.
            if (FinalDefault != XmlSchemaDerivationMethod.All)
            {
                if ((FinalDefault & XmlSchemaDerivationMethod.Substitution) != 0)
                {
                    error(handler, "substitution is not allowed in finalDefault attribute");
                }
            }

            //3. id must be of type ID
            XmlSchemaUtil.CompileID(Id, this, IDCollection, handler);

            //4. targetNamespace should be of type anyURI or absent
            if (TargetNamespace != null)
            {
                if (TargetNamespace.Length == 0)
                {
                    error(handler, "The targetNamespace attribute cannot have have empty string as its value.");
                }

                if (!XmlSchemaUtil.CheckAnyUri(TargetNamespace))
                {
                    error(handler, TargetNamespace + " is not a valid value for targetNamespace attribute of schema");
                }
            }

            //5. version should be of type normalizedString
            if (!XmlSchemaUtil.CheckNormalizedString(Version))
            {
                error(handler, Version + "is not a valid value for version attribute of schema");
            }

            // Compile the content of this schema

            for (int i = 0; i < Items.Count; i++)
            {
                compilationItems.Add(Items [i]);
            }

            // First, we run into inclusion schemas to collect
            // compilation target items into compiledItems.
            for (int i = 0; i < Includes.Count; i++)
            {
                ProcessExternal(handler, handledUris, resolver, Includes [i] as XmlSchemaExternal, col);
            }

            // Compilation phase.
            // At least each Compile() must give unique (qualified) name for each component.
            // It also checks self-resolvable properties correctness.
            // Post compilation schema information contribution is not done here.
            // It should be done by Validate().
            for (int i = 0; i < compilationItems.Count; i++)
            {
                XmlSchemaObject obj = compilationItems [i];
                if (obj is XmlSchemaAnnotation)
                {
                    int numerr = ((XmlSchemaAnnotation)obj).Compile(handler, this);
                    errorCount += numerr;
                }
                else if (obj is XmlSchemaAttribute)
                {
                    XmlSchemaAttribute attr = (XmlSchemaAttribute)obj;
                    int numerr = attr.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(Attributes, attr, attr.QualifiedName, handler);
                    }
                }
                else if (obj is XmlSchemaAttributeGroup)
                {
                    XmlSchemaAttributeGroup attrgrp = (XmlSchemaAttributeGroup)obj;
                    int numerr = attrgrp.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            AttributeGroups,
                            attrgrp,
                            attrgrp.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaComplexType)
                {
                    XmlSchemaComplexType ctype = (XmlSchemaComplexType)obj;
                    int numerr = ctype.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            schemaTypes,
                            ctype,
                            ctype.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaSimpleType)
                {
                    XmlSchemaSimpleType stype = (XmlSchemaSimpleType)obj;
                    stype.islocal = false;                     //This simple type is toplevel
                    int numerr = stype.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            SchemaTypes,
                            stype,
                            stype.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaElement)
                {
                    XmlSchemaElement elem = (XmlSchemaElement)obj;
                    elem.parentIsSchema = true;
                    int numerr = elem.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            Elements,
                            elem,
                            elem.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaGroup)
                {
                    XmlSchemaGroup grp    = (XmlSchemaGroup)obj;
                    int            numerr = grp.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            Groups,
                            grp,
                            grp.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaNotation)
                {
                    XmlSchemaNotation ntn = (XmlSchemaNotation)obj;
                    int numerr            = ntn.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            Notations,
                            ntn,
                            ntn.QualifiedName,
                            handler);
                    }
                }
                else
                {
                    ValidationHandler.RaiseValidationEvent(
                        handler,
                        null,
                        String.Format("Object of Type {0} is not valid in Item Property of Schema", obj.GetType().Name),
                        null,
                        this,
                        null,
                        XmlSeverityType.Error);
                }
            }
        }
예제 #59
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;
        }
예제 #60
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);
        }