コード例 #1
0
 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
 {
     if (this.CompilationId == schema.CompilationId)
     {
         return(0);
     }
     if (this.Content == null)
     {
         base.error(h, "Content must be present in a simpleContent");
     }
     else if (this.Content is XmlSchemaSimpleContentRestriction)
     {
         XmlSchemaSimpleContentRestriction xmlSchemaSimpleContentRestriction = (XmlSchemaSimpleContentRestriction)this.Content;
         this.errorCount += xmlSchemaSimpleContentRestriction.Compile(h, schema);
     }
     else if (this.Content is XmlSchemaSimpleContentExtension)
     {
         XmlSchemaSimpleContentExtension xmlSchemaSimpleContentExtension = (XmlSchemaSimpleContentExtension)this.Content;
         this.errorCount += xmlSchemaSimpleContentExtension.Compile(h, schema);
     }
     else
     {
         base.error(h, "simpleContent can't have any value other than restriction or extention");
     }
     XmlSchemaUtil.CompileID(base.Id, this, schema.IDCollection, h);
     this.CompilationId = schema.CompilationId;
     return(this.errorCount);
 }
コード例 #2
0
        ///<remarks>
        /// 1. Content must be present and one of restriction or extention
        ///</remarks>
        internal override int Compile(ValidationEventHandler h, XmlSchema schema)
        {
            // If this is already compiled this time, simply skip.
            if (CompilationId == schema.CompilationId)
            {
                return(0);
            }

            if (Content == null)
            {
                error(h, "Content must be present in a simpleContent");
            }
            else
            {
                if (Content is XmlSchemaSimpleContentRestriction)
                {
                    XmlSchemaSimpleContentRestriction xscr = (XmlSchemaSimpleContentRestriction)Content;
                    errorCount += xscr.Compile(h, schema);
                }
                else if (Content is XmlSchemaSimpleContentExtension)
                {
                    XmlSchemaSimpleContentExtension xsce = (XmlSchemaSimpleContentExtension)Content;
                    errorCount += xsce.Compile(h, schema);
                }
                else
                {
                    error(h, "simpleContent can't have any value other than restriction or extention");
                }
            }

            XmlSchemaUtil.CompileID(Id, this, schema.IDCollection, h);
            this.CompilationId = schema.CompilationId;
            return(errorCount);
        }
コード例 #3
0
ファイル: ClassParser.cs プロジェクト: 7digital/XsdToObject
        private void AddValueProperty(ClassInfo classInfo, XmlSchemaSimpleContentExtension sce)
        {
            var propInfo = new PropertyInfo(classInfo)
            {
                IsList = false,
                XmlName = "Value",
                XmlType = ResolveSimpleTypeName(sce.BaseTypeName.Name),
                IsElementValue = true
            };

            if (!classInfo.Elements.Contains(propInfo))
                classInfo.Elements.Add(propInfo);
        }
コード例 #4
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.");
        }
コード例 #5
0
        private void ToEmptiableSimpleContent(
            SimpleModel sm, bool isNew)
        {
            SimpleExt se = sm.Content as SimpleExt;

            if (se != null)
            {
                se.BaseTypeName = QNameString;
            }
            else
            {
                SimpleRst sr = sm.Content
                               as SimpleRst;
                if (sr == null)
                {
                    throw Error(sm, "Invalid simple content model was passed.");
                }
                sr.BaseTypeName = QNameString;
                sr.BaseType     = null;
            }
        }
コード例 #6
0
 void Write38_XmlSchemaSimpleContentExtension(XmlSchemaSimpleContentExtension o) {
     if ((object)o == null) return;
     WriteStartElement("extension");
     
     WriteAttribute(@"id", @"", ((System.String)o.@Id));
     WriteAttributes((XmlAttribute[])o.@UnhandledAttributes, o);
     if ([email protected]){
         WriteAttribute(@"base", @"", o.@BaseTypeName);
     }
     Write5_XmlSchemaAnnotation((XmlSchemaAnnotation)o.@Annotation);
     WriteSortedItems(o.Attributes);
     Write33_XmlSchemaAnyAttribute((XmlSchemaAnyAttribute)o.@AnyAttribute);
     WriteEndElement();
 }
コード例 #7
0
ファイル: infer.cs プロジェクト: krytht/DotNetReferenceSource
            internal void ProcessAttributes(ref XmlSchemaElement xse, XmlSchemaType effectiveSchemaType, bool bCreatingNewType, XmlSchema parentSchema)
            {
                XmlSchemaObjectCollection attributesSeen = new XmlSchemaObjectCollection();
                XmlSchemaComplexType ct = effectiveSchemaType as XmlSchemaComplexType;
                
                Debug.Assert(xtr.NodeType == XmlNodeType.Attribute);
                do
                {
                    if (xtr.NamespaceURI == XmlSchema.Namespace)
                    {
                        throw new XmlSchemaInferenceException(Res.SchInf_schema, 0, 0);
                    }

                    if (xtr.NamespaceURI == XmlReservedNs.NsXmlNs)
                    {
                        if (xtr.Prefix=="xmlns") 
                            NamespaceManager.AddNamespace(xtr.LocalName, xtr.Value);
                    }
                    else if (xtr.NamespaceURI == XmlReservedNs.NsXsi)
                    {
                        string localName = xtr.LocalName;
                        if (localName == "nil") 
                        {
                            xse.IsNillable = true;
                        }
                        else if (localName != "type" && localName != "schemaLocation" && localName != "noNamespaceSchemaLocation")
                        {
                            throw new XmlSchemaInferenceException(Res.Sch_NotXsiAttribute,localName);
                        }
                    }
                    else
                    {
                        if (ct == null || ct == XmlSchemaComplexType.AnyType)
                        {
                            ct = new XmlSchemaComplexType();
                            xse.SchemaType = ct;
                        }

                        XmlSchemaAttribute xsa=null;
                        //The earlier assumption of checking just schemaTypeName !Empty is not correct for schemas that are not generated by us, schemaTypeName can point to any complex type as well
                        //Check that it is a simple type by checking typeCode
                        //Switch to complex type simple content extension
                        if (effectiveSchemaType != null && effectiveSchemaType.Datatype != null && !xse.SchemaTypeName.IsEmpty)  
                        {
                            //type was previously simple type, now it will become complex with simple type extension
                            Debug.Assert(ct != null);
                            XmlSchemaSimpleContent sc = new XmlSchemaSimpleContent();
                            ct.ContentModel = sc;
                            XmlSchemaSimpleContentExtension sce = new XmlSchemaSimpleContentExtension();
                            sc.Content = sce;
                            sce.BaseTypeName = xse.SchemaTypeName;
                            sce.LineNumber = xse.LineNumber;
                            xse.LineNumber = 0;
                            xse.SchemaTypeName = XmlQualifiedName.Empty; //re-set the name
                        }
                        
                        Debug.Assert(ct != null); //either the user-defined type itself is a complex type or we switched from a simple type to a complex type
                        if (ct.ContentModel != null) 
                        {
                            XmlSchemaSimpleContentExtension sce = CheckSimpleContentExtension(ct);
                            Debug.Assert(sce != null);
                            xsa = AddAttribute(xtr.LocalName, xtr.Prefix, xtr.NamespaceURI, xtr.Value, bCreatingNewType, parentSchema, sce.Attributes, ct.AttributeUses);
                        } 
                        else //add atributes directly to complex type
                        {
                            xsa = AddAttribute(xtr.LocalName, xtr.Prefix, xtr.NamespaceURI, xtr.Value, bCreatingNewType, parentSchema, ct.Attributes, ct.AttributeUses);
                        }
                        if (xsa != null) {
                            attributesSeen.Add(xsa);
                        }
                    }
                    
                } while (xtr.MoveToNextAttribute());
                if (!bCreatingNewType)
                {   
                    //make attributes that did not appear this time optional
                    if (ct!=null) {
                        MakeExistingAttributesOptional(ct, attributesSeen);
                    }
                }
            }
 private void Write38_XmlSchemaSimpleContentExtension(XmlSchemaSimpleContentExtension o)
 {
     if (o != null)
     {
         this.WriteStartElement("extension");
         this.WriteAttribute("id", "", o.Id);
         this.WriteAttributes(o.UnhandledAttributes, o);
         if (!o.BaseTypeName.IsEmpty)
         {
             this.WriteAttribute("base", "", o.BaseTypeName);
         }
         this.Write5_XmlSchemaAnnotation(o.Annotation);
         this.WriteSortedItems(o.Attributes);
         this.Write33_XmlSchemaAnyAttribute(o.AnyAttribute);
         this.WriteEndElement();
     }
 }
コード例 #9
0
		//<extension 
		//base = QName 
		//id = ID 
		//{any attributes with non-schema namespace . . .}>
		//Content: (annotation?, ((attribute | attributeGroup)*, anyAttribute?))
		//</extension>
		internal static XmlSchemaSimpleContentExtension Read(XmlSchemaReader reader, ValidationEventHandler h)
		{
			XmlSchemaSimpleContentExtension extension = new XmlSchemaSimpleContentExtension();
			reader.MoveToElement();

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

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

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

			//Content: 1.annotation?, 2.(attribute | attributeGroup)*, 3.anyAttribute?
			int level = 1;
			while(reader.ReadNextElement())
			{
				if(reader.NodeType == XmlNodeType.EndElement)
				{
					if(reader.LocalName != xmlname)
						error(h,"Should not happen :2: XmlSchemaSimpleContentExtension.Read, name="+reader.Name,null);
					break;
				}
				if(level <= 1 && reader.LocalName == "annotation")
				{
					level = 2; //Only one annotation
					XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
					if(annotation != null)
						extension.Annotation = annotation;
					continue;
				}
				if(level <= 2)
				{
					if(reader.LocalName == "attribute")
					{
						level = 2;
						XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader,h);
						if(attr != null)
							extension.Attributes.Add(attr);
						continue;
					}
					if(reader.LocalName == "attributeGroup")
					{
						level = 2;
						XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader,h);
						if(attr != null)
							extension.attributes.Add(attr);
						continue;
					}
				}
				if(level <= 3 && reader.LocalName == "anyAttribute")
				{
					level = 4;
					XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader,h);
					if(anyattr != null)
						extension.AnyAttribute = anyattr;
					continue;
				}
				reader.RaiseInvalidElementError();
			}
			return extension;
		}
コード例 #10
0
ファイル: XmlSchemaInference.cs プロジェクト: nobled/mono
		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.");
		}
        //<extension
        //base = QName
        //id = ID
        //{any attributes with non-schema namespace . . .}>
        //Content: (annotation?, ((attribute | attributeGroup)*, anyAttribute?))
        //</extension>
        internal static XmlSchemaSimpleContentExtension Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaSimpleContentExtension extension = new XmlSchemaSimpleContentExtension();

            reader.MoveToElement();

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

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

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

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

            //Content: 1.annotation?, 2.(attribute | attributeGroup)*, 3.anyAttribute?
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaSimpleContentExtension.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (level <= 1 && reader.LocalName == "annotation")
                {
                    level = 2; //Only one annotation
                    XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h);
                    if (annotation != null)
                    {
                        extension.Annotation = annotation;
                    }
                    continue;
                }
                if (level <= 2)
                {
                    if (reader.LocalName == "attribute")
                    {
                        level = 2;
                        XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader, h);
                        if (attr != null)
                        {
                            extension.Attributes.Add(attr);
                        }
                        continue;
                    }
                    if (reader.LocalName == "attributeGroup")
                    {
                        level = 2;
                        XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader, h);
                        if (attr != null)
                        {
                            extension.attributes.Add(attr);
                        }
                        continue;
                    }
                }
                if (level <= 3 && reader.LocalName == "anyAttribute")
                {
                    level = 4;
                    XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader, h);
                    if (anyattr != null)
                    {
                        extension.AnyAttribute = anyattr;
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(extension);
        }
コード例 #12
0
 XmlSchemaAttribute FindAttribute(XmlSchemaSimpleContentExtension extension, string name)
 {
     return FindAttribute(extension.Attributes, name);
 }
コード例 #13
0
        void ExportTypeMembers(XmlSchemaComplexType type, MemberMapping[] members, string name, string ns, bool hasSimpleContent, bool openModel) {
            XmlSchemaGroupBase seq = new XmlSchemaSequence();
            TypeMapping textMapping = null;
            
            for (int i = 0; i < members.Length; i++) {
                MemberMapping member = members[i];
                if (member.Ignore)
                    continue;
                if (member.Text != null) {
                    if (textMapping != null) {
                        throw new InvalidOperationException(Res.GetString(Res.XmlIllegalMultipleText, name));
                    }
                    textMapping = member.Text.Mapping;
                }
                if (member.Elements.Length > 0) {
                    bool repeats = member.TypeDesc.IsArrayLike && 
                        !(member.Elements.Length == 1 && member.Elements[0].Mapping is ArrayMapping);

                    bool valueTypeOptional = member.CheckSpecified != SpecifiedAccessor.None || member.CheckShouldPersist;
                    ExportElementAccessors(seq, member.Elements, repeats, valueTypeOptional, ns);
                }
            }

            if (seq.Items.Count > 0) {
                if (type.ContentModel != null) {
                    if (type.ContentModel.Content is XmlSchemaComplexContentRestriction)
                        ((XmlSchemaComplexContentRestriction)type.ContentModel.Content).Particle = seq;
                    else if (type.ContentModel.Content is XmlSchemaComplexContentExtension)
                        ((XmlSchemaComplexContentExtension)type.ContentModel.Content).Particle = seq;
                    else
                        throw new InvalidOperationException(Res.GetString(Res.XmlInvalidContent, type.ContentModel.Content.GetType().Name));
                }
                else {
                    type.Particle = seq;
                }
            }
            if (textMapping != null) {
                if (hasSimpleContent) {
                    if (textMapping is PrimitiveMapping && seq.Items.Count == 0) {
                        PrimitiveMapping pm = (PrimitiveMapping)textMapping;
                        if (pm.IsList) {
                            type.IsMixed = true;
                        }
                        else {
                            if (pm.IsAnonymousType) {
                                throw new InvalidOperationException(Res.GetString(Res.XmlAnonymousBaseType, textMapping.TypeDesc.Name, pm.TypeDesc.Name, "AnonymousType", "false"));
                            }
                            // Create simpleContent
                            XmlSchemaSimpleContent model = new XmlSchemaSimpleContent();
                            XmlSchemaSimpleContentExtension ex = new XmlSchemaSimpleContentExtension();
                            model.Content = ex;
                            type.ContentModel = model;
                            ex.BaseTypeName = ExportPrimitiveMapping(pm, ns);
                        }
                    }
                }
                else {
                    type.IsMixed = true;
                }
            }
            bool anyAttribute = false;
            for (int i = 0; i < members.Length; i++) {
                AttributeAccessor accessor = members[i].Attribute;
                if (accessor != null) {
                    ExportAttributeAccessor(type, members[i].Attribute, members[i].CheckSpecified != SpecifiedAccessor.None || members[i].CheckShouldPersist, ns);
                    if (members[i].Attribute.Any)
                        anyAttribute = true;
                }
            }
            if (openModel && !anyAttribute) {
                AttributeAccessor any = new AttributeAccessor();
                any.Any = true;
                ExportAttributeAccessor(type, any, false, ns);
            }
        }
コード例 #14
0
ファイル: Program.cs プロジェクト: stephenwelsh/msiext
 private static string ProcessSchemaSimpleContentExtension(XmlSchemaSimpleContentExtension schemaContentExtension)
 {
     StringBuilder result = new StringBuilder();
     //if (schemaContentExtension.Annotation != null)
     //{
     //    result.AppendLine("May have nested data.");
     //    result.Append(ProcessAnnotation(schemaContentExtension.Annotation));
     //}
     result.Append(Process(schemaContentExtension.Attributes));
     return result.ToString();
 }
コード例 #15
0
		public override void Check (ConformanceCheckContext ctx, XmlSchemaSimpleContentExtension value)
		{
			CheckSchemaQName (ctx, value, value.BaseTypeName);
		}
コード例 #16
0
ファイル: ConformanceChecker.cs プロジェクト: nobled/mono
		public virtual void Check (ConformanceCheckContext ctx, XmlSchemaSimpleContentExtension value) {}
コード例 #17
0
 private void MoveAttributes(XmlSchemaSimpleContentExtension scExtension,  XmlSchemaComplexType ct) {
     //copy all attributes from the simple content to the complex type
     //This is ok since when we move from complex type to simple content extension we copy from AttributeUses property
     foreach (XmlSchemaAttribute attr in scExtension.Attributes) { //since simpleContent is being cleared 
         ct.Attributes.Add(attr);
     }
 }
コード例 #18
0
        internal static XmlSchemaSimpleContent Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaSimpleContent xmlSchemaSimpleContent = new XmlSchemaSimpleContent();

            reader.MoveToElement();
            if (reader.NamespaceURI != "http://www.w3.org/2001/XMLSchema" || reader.LocalName != "simpleContent")
            {
                XmlSchemaObject.error(h, "Should not happen :1: XmlSchemaComplexContent.Read, name=" + reader.Name, null);
                reader.SkipToEnd();
                return(null);
            }
            xmlSchemaSimpleContent.LineNumber   = reader.LineNumber;
            xmlSchemaSimpleContent.LinePosition = reader.LinePosition;
            xmlSchemaSimpleContent.SourceUri    = reader.BaseURI;
            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    xmlSchemaSimpleContent.Id = 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 simpleContent", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, xmlSchemaSimpleContent);
                }
            }
            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(xmlSchemaSimpleContent);
            }
            int num = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != "simpleContent")
                    {
                        XmlSchemaObject.error(h, "Should not happen :2: XmlSchemaSimpleContent.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (num <= 1 && reader.LocalName == "annotation")
                {
                    num = 2;
                    XmlSchemaAnnotation xmlSchemaAnnotation = XmlSchemaAnnotation.Read(reader, h);
                    if (xmlSchemaAnnotation != null)
                    {
                        xmlSchemaSimpleContent.Annotation = xmlSchemaAnnotation;
                    }
                }
                else
                {
                    if (num <= 2)
                    {
                        if (reader.LocalName == "restriction")
                        {
                            num = 3;
                            XmlSchemaSimpleContentRestriction xmlSchemaSimpleContentRestriction = XmlSchemaSimpleContentRestriction.Read(reader, h);
                            if (xmlSchemaSimpleContentRestriction != null)
                            {
                                xmlSchemaSimpleContent.content = xmlSchemaSimpleContentRestriction;
                            }
                            continue;
                        }
                        if (reader.LocalName == "extension")
                        {
                            num = 3;
                            XmlSchemaSimpleContentExtension xmlSchemaSimpleContentExtension = XmlSchemaSimpleContentExtension.Read(reader, h);
                            if (xmlSchemaSimpleContentExtension != null)
                            {
                                xmlSchemaSimpleContent.content = xmlSchemaSimpleContentExtension;
                            }
                            continue;
                        }
                    }
                    reader.RaiseInvalidElementError();
                }
            }
            return(xmlSchemaSimpleContent);
        }
コード例 #19
0
ファイル: infer.cs プロジェクト: krytht/DotNetReferenceSource
 private void MoveAttributes(XmlSchemaComplexType ct, XmlSchemaSimpleContentExtension simpleContentExtension, bool bCreatingNewType) {
     //copy all attributes from the complex type to the simple content
     
     ICollection sourceCollection;
     if (!bCreatingNewType && ct.AttributeUses.Count > 0) {
         sourceCollection = ct.AttributeUses.Values;
     }
     else {
         sourceCollection = ct.Attributes;
     }
     
     foreach (XmlSchemaAttribute attr in sourceCollection) {
         simpleContentExtension.Attributes.Add(attr);
     }
     ct.Attributes.Clear(); //Clear from pre-compiled property, post compiled will be cleared on Re-process and Compile()
 }
コード例 #20
0
		XmlCompletionDataCollection GetAttributeCompletionData(XmlSchemaSimpleContentExtension extension)
		{
			XmlCompletionDataCollection data = new XmlCompletionDataCollection();
									
			data.AddRange(GetAttributeCompletionData(extension.Attributes));

			return data;
		}		
コード例 #21
0
 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;
 }
コード例 #22
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.");
        }
コード例 #23
0
        static void AddScopesType(DiscoveryVersion discoveryVersion, XmlSchema schema)
        {
            // <xs:complexType name="ScopesType">
            XmlSchemaComplexType scopesType = new XmlSchemaComplexType();
            scopesType.Name = ProtocolStrings.SchemaNames.ScopesType;

            //    <xs:simpleContent>
            XmlSchemaSimpleContent scopesTypeContent = new XmlSchemaSimpleContent();

            //       <xs:extension base="tns:UriListType">
            XmlSchemaSimpleContentExtension scopesTypeContentExtension = new XmlSchemaSimpleContentExtension();
            scopesTypeContentExtension.BaseTypeName = discoveryVersion.Implementation.QualifiedNames.UriListType;

            //          <xs:attribute name="MatchBy" type="xs:anyURI" />    
            XmlSchemaAttribute matchBy = new XmlSchemaAttribute();
            matchBy.Name = ProtocolStrings.SchemaNames.MatchByAttribute;
            matchBy.SchemaTypeName = discoveryVersion.Implementation.QualifiedNames.AnyUriType;

            //          <xs:anyAttribute namespace="##other" processContents="lax" />
            XmlSchemaAnyAttribute anyAttribute = new XmlSchemaAnyAttribute();
            anyAttribute.Namespace = "##other";
            anyAttribute.ProcessContents = XmlSchemaContentProcessing.Lax;

            //       </xs:extension>
            scopesTypeContentExtension.Attributes.Add(matchBy);
            scopesTypeContentExtension.AnyAttribute = anyAttribute;

            //    </xs:simpleContent>
            scopesTypeContent.Content = scopesTypeContentExtension;

            // <xs:complexType name="ScopesType">
            scopesType.ContentModel = scopesTypeContent;

            schema.Items.Add(scopesType);
        }
コード例 #24
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;
            }
        }
コード例 #25
0
		XmlCompletionItemCollection GetAttributeCompletion(XmlSchemaSimpleContentExtension extension, XmlNamespaceCollection namespacesInScope)
		{
			XmlCompletionItemCollection completionItems = new XmlCompletionItemCollection();
			
			completionItems.AddRange(GetAttributeCompletion(extension.Attributes, namespacesInScope));
			completionItems.AddRange(GetBaseComplexTypeAttributeCompletion(extension.BaseTypeName, namespacesInScope));
			
			return completionItems;
		}
 private XmlQualifiedName ExportStructMapping(StructMapping mapping, string ns, XmlSchemaElement element)
 {
     if (mapping.TypeDesc.IsRoot)
     {
         this.needToExportRoot = true;
         return XmlQualifiedName.Empty;
     }
     if (mapping.IsAnonymousType)
     {
         if (this.references[mapping] != null)
         {
             throw new InvalidOperationException(Res.GetString("XmlCircularReference2", new object[] { mapping.TypeDesc.Name, "AnonymousType", "false" }));
         }
         this.references[mapping] = mapping;
     }
     XmlSchemaComplexType item = (XmlSchemaComplexType) this.types[mapping];
     if (item == null)
     {
         if (!mapping.IncludeInSchema)
         {
             throw new InvalidOperationException(Res.GetString("XmlCannotIncludeInSchema", new object[] { mapping.TypeDesc.Name }));
         }
         this.CheckForDuplicateType(mapping, mapping.Namespace);
         item = new XmlSchemaComplexType();
         if (!mapping.IsAnonymousType)
         {
             item.Name = mapping.TypeName;
             this.AddSchemaItem(item, mapping.Namespace, ns);
             this.types.Add(mapping, item);
         }
         item.IsAbstract = mapping.TypeDesc.IsAbstract;
         bool isOpenModel = mapping.IsOpenModel;
         if ((mapping.BaseMapping != null) && mapping.BaseMapping.IncludeInSchema)
         {
             if (mapping.BaseMapping.IsAnonymousType)
             {
                 throw new InvalidOperationException(Res.GetString("XmlAnonymousBaseType", new object[] { mapping.TypeDesc.Name, mapping.BaseMapping.TypeDesc.Name, "AnonymousType", "false" }));
             }
             if (mapping.HasSimpleContent)
             {
                 XmlSchemaSimpleContent content = new XmlSchemaSimpleContent();
                 XmlSchemaSimpleContentExtension extension = new XmlSchemaSimpleContentExtension {
                     BaseTypeName = this.ExportStructMapping(mapping.BaseMapping, mapping.Namespace, null)
                 };
                 content.Content = extension;
                 item.ContentModel = content;
             }
             else
             {
                 XmlSchemaComplexContentExtension extension2 = new XmlSchemaComplexContentExtension {
                     BaseTypeName = this.ExportStructMapping(mapping.BaseMapping, mapping.Namespace, null)
                 };
                 XmlSchemaComplexContent content2 = new XmlSchemaComplexContent {
                     Content = extension2,
                     IsMixed = XmlSchemaImporter.IsMixed((XmlSchemaComplexType) this.types[mapping.BaseMapping])
                 };
                 item.ContentModel = content2;
             }
             isOpenModel = false;
         }
         this.ExportTypeMembers(item, mapping.Members, mapping.TypeName, mapping.Namespace, mapping.HasSimpleContent, isOpenModel);
         this.ExportDerivedMappings(mapping);
         if (mapping.XmlnsMember != null)
         {
             this.AddXmlnsAnnotation(item, mapping.XmlnsMember.Name);
         }
     }
     else
     {
         this.AddSchemaImport(mapping.Namespace, ns);
     }
     if (mapping.IsAnonymousType)
     {
         this.references[mapping] = null;
         if (element != null)
         {
             element.SchemaType = item;
         }
         return XmlQualifiedName.Empty;
     }
     XmlQualifiedName name = new XmlQualifiedName(item.Name, mapping.Namespace);
     if (element != null)
     {
         element.SchemaTypeName = name;
     }
     return name;
 }
コード例 #27
0
 protected override void Visit(XmlSchemaSimpleContentExtension extension)
 {
     ProcessExtension(extension.BaseTypeName, extension.Attributes, extension.AnyAttribute);
 }
コード例 #28
0
ファイル: ModifyXsd.cs プロジェクト: PavelPZ/NetNew
    public static void genSchema() {
      //merge DOC to tagsMeta
      doc.export();
      //modify xhtml5.xsd
      XmlSchema schema;
      using (var str = File.OpenRead(@"d:\LMCom\rew\Web4\Author\xhtml5.xsd")) schema = XmlSchema.Read(str, null);
      var meta = Lib.courseModelJsonMLMeta;
      XmlSchemaAttributeGroup attrGrp;
      var allTypes = meta.types.Values.Where(t => (t.st & (tgSt.xsdIgnore | tgSt.obsolete)) == 0).ToArray();
      Func<jsClassMeta, IEnumerable<jsPropMeta>> myXsdProps = tp => tp.props.Values.Where(p => (p.st & (tgSt.xsdIgnore | tgSt.xmlIgnore)) == 0);
      Func<jsClassMeta, IEnumerable<jsPropMeta>> allXsdProps = tp => tp.parents(true).Where(t => (tp.st & (tgSt.xsdIgnoreTagAttrs /*| tgSt.xsdHtmlEl*/))!=0 ? t.name!="tag" : true).SelectMany(t => myXsdProps(t));
      //Func<jsClassMeta, IEnumerable<jsPropMeta>> allXsdPropsNoTag = tp => tp.parents(true).Where(t => t.name != "tag").SelectMany(t => myXsdProps(t));
      XmlSchemaComplexType complex; XmlSchemaSimpleContentExtension simpleExt;
      XmlSchemaChoice choice; XmlSchemaGroupBase grpBase;

      //*************** modifikace HTML 5 atributu a childs
      //definice parent-prop a style-sheet atributu
      schema.Items.Add(attrGrp = new XmlSchemaAttributeGroup { Name = "LM-spec-attrs" });
      //attrGrp.Attributes.Add(new XmlSchemaAttribute { Name = "parent-prop", SchemaTypeName = new XmlQualifiedName("parentProps"), DefaultValue = "no" });
      attrGrp.Attributes.Add(new XmlSchemaAttribute { Name = "style-sheet", SchemaTypeName = stringType });
      attrGrp.Attributes.Add(new XmlSchemaAttribute { Name = "data-bind", SchemaTypeName = stringType });

      //definice grupy pro all LM elements
      schema.Items.Add(new XmlSchemaGroup { Name = "LM-all-elements", Particle = choice = new XmlSchemaChoice() });
      foreach (var typ in allTypes.Where(t => (t.st & tgSt.xsdNoGlobal)==0)) choice.Items.Add(new XmlSchemaElement { RefName = new XmlQualifiedName(typ.tagName) });

      //modifikace commonPhrasingElements groups
      var commGrp = schema.Items.OfType<XmlSchemaGroup>().First(e => e.Name == "commonPhrasingElements");
      ((XmlSchemaChoice)commGrp.Particle).Items.Add(new XmlSchemaGroupRef { RefName = new XmlQualifiedName("LM-all-elements") });

      //modifikace coreAttributeGroupNodir o tag attribute group
      attrGrp = schema.Items.OfType<XmlSchemaAttributeGroup>().First(e => e.Name == "coreAttributeGroupNodir");
      attrGrp.Attributes.Add(new XmlSchemaAttributeGroupRef { RefName = new XmlQualifiedName("LM-spec-attrs") });

      //*************** dalse modifikace HTML 5
      //modifikace id atributu z token na xs:ID
      var idType = schema.Items.OfType<XmlSchemaSimpleType>().First(e => e.Name == "id");
      ((XmlSchemaSimpleTypeRestriction)idType.Content).BaseTypeName = new XmlQualifiedName("xs:ID");

      //modifikace body
      var body = schema.Items.OfType<XmlSchemaElement>().First(e => e.Name == "body");
      var ext = (XmlSchemaComplexContentExtension)((XmlSchemaComplexContent)((XmlSchemaComplexType)body.SchemaType).ContentModel).Content;
      foreach (var prop in myXsdProps(meta.types["body"])) ext.Attributes.Add(generateProp(prop));

      //modifikace li
      schema.Items.Add(new XmlSchemaElement { Name="li", SchemaTypeName = new XmlQualifiedName("li") });

      //*************** LM elements
      //RegEx "and-*-exchangeable" pro jmeno eval grupy
      XmlSchemaSimpleTypeRestriction restr;
      schema.Items.Add(new XmlSchemaSimpleType {
        Name = evalControl.xsdType_eval_group,
        Content = restr = new XmlSchemaSimpleTypeRestriction { BaseTypeName = new XmlQualifiedName("xs:string") }
      });
      restr.Facets.Add(new XmlSchemaPatternFacet { Value = evalControl.xsdType_eval_group_regex });

      //RegEx sequence zvukovuch vet
      schema.Items.Add(new XmlSchemaSimpleType {
        Name = _sndFile.mediaTag_sequence,
        Content = restr = new XmlSchemaSimpleTypeRestriction { BaseTypeName = new XmlQualifiedName("xs:string") }
      });
      restr.Facets.Add(new XmlSchemaPatternFacet { Value = _sndFile.mediaTag_sequence_regex });

      //RegEx format videa
      schema.Items.Add(new XmlSchemaSimpleType {
        Name = urlTag.mediaTag_format,
        Content = restr = new XmlSchemaSimpleTypeRestriction { BaseTypeName = new XmlQualifiedName("xs:string") }
      });
      restr.Facets.Add(new XmlSchemaPatternFacet { Value = urlTag.mediaTag_format_regex });

      //RegEx identifikace zvukove vety v dialogu
      schema.Items.Add(new XmlSchemaSimpleType {
        Name = phraseReplace.sndReplace_sndDialogIdx,
        Content = restr = new XmlSchemaSimpleTypeRestriction { BaseTypeName = new XmlQualifiedName("xs:string") }
      });
      restr.Facets.Add(new XmlSchemaPatternFacet { Value = phraseReplace.sndReplace_sndDialogIdx_regex });

      //lm typy
      foreach (var typ in allTypes) {
        if (typ.name == "sndDialog") {
          if (typ == null) return;
        }
        schema.Items.Add(new XmlSchemaElement { Name = typ.tagName, SchemaTypeName = new XmlQualifiedName(typ.tagName + "-type") });
        //element type
        if ((typ.st & tgSt.xsdHtmlEl) != 0) { //odvozeno z HTML
          var isMixed = (typ.st & tgSt.xsdNoMixed) == 0; //mixed?
          schema.Items.Add(complex = new XmlSchemaComplexType {
            Name = typ.tagName + "-type",
            IsMixed = isMixed,
            Particle = grpBase = new XmlSchemaSequence { MinOccurs = 0, MaxOccursString = "unbounded" }
          });
          grpBase.Items.Add(new XmlSchemaGroupRef { RefName = new XmlQualifiedName("flowContent") });
          //foreach (var p in allXsdPropsNoTag(typ)) complex.Attributes.Add(generateProp(p));
          foreach (var p in allXsdProps(typ)) complex.Attributes.Add(generateProp(p));
          continue;
        }
        if ((typ.st & (tgSt.xsdString | tgSt.cdata)) != 0) { //pouze string content (nebo cdata)
          schema.Items.Add(complex = new XmlSchemaComplexType {
            Name = typ.tagName + "-type",
            ContentModel = new XmlSchemaSimpleContent { Content = simpleExt = new XmlSchemaSimpleContentExtension { BaseTypeName = new XmlQualifiedName("xs:string") } }
          });
          foreach (var p in allXsdProps(typ)) simpleExt.Attributes.Add(generateProp(p));
          continue;
        }
        if (!string.IsNullOrEmpty(typ.xsdChildElements)) { //explixitne nadefinovane child elements
          var childs = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>("{" + typ.xsdChildElements + "}");
          //var obj = childs as JObject;
          //var prop = obj.Properties().FirstOrDefault();
          //var arr = prop.Value as JArray;
          schema.Items.Add(complex = new XmlSchemaComplexType {
            Name = typ.tagName + "-type",
            IsMixed = (typ.st & tgSt.xsdMixed)!=0,
            Particle = genChilds(Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>("{" + typ.xsdChildElements + "}")) as XmlSchemaParticle//choice = new XmlSchemaChoice { MaxOccursString = "unbounded", MinOccurs=0 }
          });
          //foreach (var t in typ.xsdChildElements.Split('|')) choice.Items.Add(new XmlSchemaElement { RefName = new XmlQualifiedName(t) });
          //foreach (var t in typ.xsdChildElements.Split('|')) choice.Items.Add(new XmlSchemaElement { Name = t });
          foreach (var p in allXsdProps(typ)) complex.Attributes.Add(generateProp(p));
          continue;
        }
        schema.Items.Add(complex = new XmlSchemaComplexType { Name = typ.tagName + "-type" });
        foreach (var p in allXsdProps(typ)) complex.Attributes.Add(generateProp(p));
      }

      //lm enums
      foreach (var en in getAll.Enums()) generateEnum(schema, en);

      //schema.Compile((s, a) => { });
      if (File.Exists(schemaFn)) File.Delete(schemaFn);
      using (var str = File.OpenWrite(schemaFn)) schema.Write(str);
    }
コード例 #29
0
        internal static XmlSchemaSimpleContentExtension Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaSimpleContentExtension xmlSchemaSimpleContentExtension = new XmlSchemaSimpleContentExtension();

            reader.MoveToElement();
            if (reader.NamespaceURI != "http://www.w3.org/2001/XMLSchema" || reader.LocalName != "extension")
            {
                XmlSchemaObject.error(h, "Should not happen :1: XmlSchemaAttributeGroup.Read, name=" + reader.Name, null);
                reader.Skip();
                return(null);
            }
            xmlSchemaSimpleContentExtension.LineNumber   = reader.LineNumber;
            xmlSchemaSimpleContentExtension.LinePosition = reader.LinePosition;
            xmlSchemaSimpleContentExtension.SourceUri    = reader.BaseURI;
            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "base")
                {
                    Exception ex;
                    xmlSchemaSimpleContentExtension.baseTypeName = XmlSchemaUtil.ReadQNameAttribute(reader, out ex);
                    if (ex != null)
                    {
                        XmlSchemaObject.error(h, reader.Value + " is not a valid value for base attribute", ex);
                    }
                }
                else if (reader.Name == "id")
                {
                    xmlSchemaSimpleContentExtension.Id = 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 extension in this context", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, xmlSchemaSimpleContentExtension);
                }
            }
            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(xmlSchemaSimpleContentExtension);
            }
            int num = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != "extension")
                    {
                        XmlSchemaObject.error(h, "Should not happen :2: XmlSchemaSimpleContentExtension.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (num <= 1 && reader.LocalName == "annotation")
                {
                    num = 2;
                    XmlSchemaAnnotation xmlSchemaAnnotation = XmlSchemaAnnotation.Read(reader, h);
                    if (xmlSchemaAnnotation != null)
                    {
                        xmlSchemaSimpleContentExtension.Annotation = xmlSchemaAnnotation;
                    }
                }
                else
                {
                    if (num <= 2)
                    {
                        if (reader.LocalName == "attribute")
                        {
                            num = 2;
                            XmlSchemaAttribute xmlSchemaAttribute = XmlSchemaAttribute.Read(reader, h);
                            if (xmlSchemaAttribute != null)
                            {
                                xmlSchemaSimpleContentExtension.Attributes.Add(xmlSchemaAttribute);
                            }
                            continue;
                        }
                        if (reader.LocalName == "attributeGroup")
                        {
                            num = 2;
                            XmlSchemaAttributeGroupRef xmlSchemaAttributeGroupRef = XmlSchemaAttributeGroupRef.Read(reader, h);
                            if (xmlSchemaAttributeGroupRef != null)
                            {
                                xmlSchemaSimpleContentExtension.attributes.Add(xmlSchemaAttributeGroupRef);
                            }
                            continue;
                        }
                    }
                    if (num <= 3 && reader.LocalName == "anyAttribute")
                    {
                        num = 4;
                        XmlSchemaAnyAttribute xmlSchemaAnyAttribute = XmlSchemaAnyAttribute.Read(reader, h);
                        if (xmlSchemaAnyAttribute != null)
                        {
                            xmlSchemaSimpleContentExtension.AnyAttribute = xmlSchemaAnyAttribute;
                        }
                    }
                    else
                    {
                        reader.RaiseInvalidElementError();
                    }
                }
            }
            return(xmlSchemaSimpleContentExtension);
        }
コード例 #30
0
 protected override void Visit(XmlSchemaSimpleContentExtension extension)
 {
     TraverseBaseType(extension.BaseTypeName);
 }
 private void ExportTypeMembers(XmlSchemaComplexType type, MemberMapping[] members, string name, string ns, bool hasSimpleContent, bool openModel)
 {
     XmlSchemaGroupBase group = new XmlSchemaSequence();
     TypeMapping mapping = null;
     for (int i = 0; i < members.Length; i++)
     {
         MemberMapping mapping2 = members[i];
         if (!mapping2.Ignore)
         {
             if (mapping2.Text != null)
             {
                 if (mapping != null)
                 {
                     throw new InvalidOperationException(Res.GetString("XmlIllegalMultipleText", new object[] { name }));
                 }
                 mapping = mapping2.Text.Mapping;
             }
             if (mapping2.Elements.Length > 0)
             {
                 bool repeats = mapping2.TypeDesc.IsArrayLike && ((mapping2.Elements.Length != 1) || !(mapping2.Elements[0].Mapping is ArrayMapping));
                 bool valueTypeOptional = (mapping2.CheckSpecified != SpecifiedAccessor.None) || mapping2.CheckShouldPersist;
                 this.ExportElementAccessors(group, mapping2.Elements, repeats, valueTypeOptional, ns);
             }
         }
     }
     if (group.Items.Count > 0)
     {
         if (type.ContentModel != null)
         {
             if (type.ContentModel.Content is XmlSchemaComplexContentRestriction)
             {
                 ((XmlSchemaComplexContentRestriction) type.ContentModel.Content).Particle = group;
             }
             else
             {
                 if (!(type.ContentModel.Content is XmlSchemaComplexContentExtension))
                 {
                     throw new InvalidOperationException(Res.GetString("XmlInvalidContent", new object[] { type.ContentModel.Content.GetType().Name }));
                 }
                 ((XmlSchemaComplexContentExtension) type.ContentModel.Content).Particle = group;
             }
         }
         else
         {
             type.Particle = group;
         }
     }
     if (mapping != null)
     {
         if (hasSimpleContent)
         {
             if ((mapping is PrimitiveMapping) && (group.Items.Count == 0))
             {
                 PrimitiveMapping mapping3 = (PrimitiveMapping) mapping;
                 if (mapping3.IsList)
                 {
                     type.IsMixed = true;
                 }
                 else
                 {
                     if (mapping3.IsAnonymousType)
                     {
                         throw new InvalidOperationException(Res.GetString("XmlAnonymousBaseType", new object[] { mapping.TypeDesc.Name, mapping3.TypeDesc.Name, "AnonymousType", "false" }));
                     }
                     XmlSchemaSimpleContent content = new XmlSchemaSimpleContent();
                     XmlSchemaSimpleContentExtension extension = new XmlSchemaSimpleContentExtension();
                     content.Content = extension;
                     type.ContentModel = content;
                     extension.BaseTypeName = this.ExportPrimitiveMapping(mapping3, ns);
                 }
             }
         }
         else
         {
             type.IsMixed = true;
         }
     }
     bool flag3 = false;
     for (int j = 0; j < members.Length; j++)
     {
         if (members[j].Attribute != null)
         {
             this.ExportAttributeAccessor(type, members[j].Attribute, (members[j].CheckSpecified != SpecifiedAccessor.None) || members[j].CheckShouldPersist, ns);
             if (members[j].Attribute.Any)
             {
                 flag3 = true;
             }
         }
     }
     if (openModel && !flag3)
     {
         AttributeAccessor accessor = new AttributeAccessor {
             Any = true
         };
         this.ExportAttributeAccessor(type, accessor, false, ns);
     }
 }
コード例 #32
0
ファイル: XmlSchemaExporter.cs プロジェクト: Profit0004/mono
		void ExportClassSchema (XmlTypeMapping map)
		{
			if (IsMapExported (map)) return;
			SetMapExported (map);
			
			if (map.TypeData.Type == typeof(object))
			{
				foreach (XmlTypeMapping dmap in map.DerivedTypes)
					if (dmap.TypeData.SchemaType == SchemaTypes.Class) ExportClassSchema (dmap);
				return;
			}

			XmlSchema schema = GetSchema (map.XmlTypeNamespace);
			XmlSchemaComplexType stype = new XmlSchemaComplexType ();
			stype.Name = map.XmlType;
			schema.Items.Add (stype);

			ClassMap cmap = (ClassMap)map.ObjectMap;

			if (cmap.HasSimpleContent)
			{
				XmlSchemaSimpleContent simple = new XmlSchemaSimpleContent ();
				stype.ContentModel = simple;
				XmlSchemaSimpleContentExtension ext = new XmlSchemaSimpleContentExtension ();
				simple.Content = ext;
				XmlSchemaSequence particle;
				XmlSchemaAnyAttribute anyAttribute;
				ExportMembersMapSchema (schema, cmap, map.BaseMap, ext.Attributes, out particle, out anyAttribute);
				ext.AnyAttribute = anyAttribute;
				if (map.BaseMap == null)
					ext.BaseTypeName = cmap.SimpleContentBaseType;
				else {
					ext.BaseTypeName = new XmlQualifiedName (map.BaseMap.XmlType, map.BaseMap.XmlTypeNamespace);
					ImportNamespace (schema, map.BaseMap.XmlTypeNamespace);
					ExportClassSchema (map.BaseMap);
				}
			}
			else if (map.BaseMap != null && map.BaseMap.IncludeInSchema)
			{
				XmlSchemaComplexContent cstype = new XmlSchemaComplexContent ();
				XmlSchemaComplexContentExtension ext = new XmlSchemaComplexContentExtension ();
				ext.BaseTypeName = new XmlQualifiedName (map.BaseMap.XmlType, map.BaseMap.XmlTypeNamespace);
				cstype.Content = ext;
				stype.ContentModel = cstype;

				XmlSchemaSequence particle;
				XmlSchemaAnyAttribute anyAttribute;
				ExportMembersMapSchema (schema, cmap, map.BaseMap, ext.Attributes, out particle, out anyAttribute);
				ext.Particle = particle;
				ext.AnyAttribute = anyAttribute;
				stype.IsMixed = HasMixedContent (map);
				cstype.IsMixed = BaseHasMixedContent (map);

				ImportNamespace (schema, map.BaseMap.XmlTypeNamespace);
				ExportClassSchema (map.BaseMap);
			}
			else
			{
				XmlSchemaSequence particle;
				XmlSchemaAnyAttribute anyAttribute;
				ExportMembersMapSchema (schema, cmap, map.BaseMap, stype.Attributes, out particle, out anyAttribute);
				stype.Particle = particle;
				stype.AnyAttribute = anyAttribute;
				stype.IsMixed = cmap.XmlTextCollector != null;
			}
			
			foreach (XmlTypeMapping dmap in map.DerivedTypes)
				if (dmap.TypeData.SchemaType == SchemaTypes.Class) ExportClassSchema (dmap);
		}
コード例 #33
0
 private void CompileSimpleContentExtension(XmlSchemaComplexType complexType, XmlSchemaSimpleContentExtension simpleExtension) {
     XmlSchemaComplexType baseType = null;
     if (complexType.Redefined != null && simpleExtension.BaseTypeName == complexType.Redefined.QualifiedName) {
         baseType = (XmlSchemaComplexType)complexType.Redefined;
         CompileComplexType(baseType);
         complexType.SetBaseSchemaType(baseType);
         complexType.SetDatatype(baseType.Datatype);
     }
     else {
         XmlSchemaType bto = GetAnySchemaType(simpleExtension.BaseTypeName);
         if (bto == null) {
             SendValidationEvent(Res.Sch_UndeclaredType, simpleExtension.BaseTypeName.ToString(), simpleExtension);   
         } 
         else {
             complexType.SetBaseSchemaType(bto);
             complexType.SetDatatype(bto.Datatype);
         }
         baseType = bto as XmlSchemaComplexType;
     }
     if (baseType != null) {
         if ((baseType.FinalResolved & XmlSchemaDerivationMethod.Extension) != 0) {
             SendValidationEvent(Res.Sch_BaseFinalExtension, complexType);
         }
         if (baseType.ContentType != XmlSchemaContentType.TextOnly) {
             SendValidationEvent(Res.Sch_NotSimpleContent, complexType);
         }
     } 
     complexType.SetDerivedBy(XmlSchemaDerivationMethod.Extension);
     CompileLocalAttributes(baseType, complexType, simpleExtension.Attributes, simpleExtension.AnyAttribute, XmlSchemaDerivationMethod.Extension);
 }
コード例 #34
0
		void GetAttributeCompletionData (XmlCompletionDataList data, XmlSchemaSimpleContentExtension extension)
		{
			GetAttributeCompletionData (data, extension.Attributes);
		}		
コード例 #35
0
ファイル: XsdBuilder.cs プロジェクト: uQr/referencesource
 private void SetContainer(State state, object container) {
     switch (state) {
         case State.Root:
             break;
         case State.Schema:
             break;
         case State.Annotation:
             this.annotation = (XmlSchemaAnnotation)container;
             break;
         case State.Include:
             this.include = (XmlSchemaInclude)container;
             break;
         case State.Import:
             this.import = (XmlSchemaImport)container;
             break;
         case State.Element:
             this.element = (XmlSchemaElement)container;
             break;
         case State.Attribute:
             this.attribute = (XmlSchemaAttribute)container;
             break;
         case State.AttributeGroup:
             this.attributeGroup = (XmlSchemaAttributeGroup)container;
             break;
         case State.AttributeGroupRef:
             this.attributeGroupRef = (XmlSchemaAttributeGroupRef)container;
             break;
         case State.AnyAttribute:
             this.anyAttribute = (XmlSchemaAnyAttribute)container;
             break;
         case State.Group:
             this.group = (XmlSchemaGroup)container;
             break;
         case State.GroupRef:
             this.groupRef = (XmlSchemaGroupRef)container;
             break;
         case State.All:
             this.all = (XmlSchemaAll)container;
             break;
         case State.Choice:
             this.choice = (XmlSchemaChoice)container;
             break;
         case State.Sequence:
             this.sequence = (XmlSchemaSequence)container;
             break;
         case State.Any:
             this.anyElement = (XmlSchemaAny)container;
             break;
         case State.Notation:
             this.notation = (XmlSchemaNotation)container;
             break;
         case State.SimpleType:
             this.simpleType = (XmlSchemaSimpleType)container;
             break;
         case State.ComplexType:
             this.complexType = (XmlSchemaComplexType)container;
             break;
         case State.ComplexContent:
             this.complexContent = (XmlSchemaComplexContent)container;
             break;
         case State.ComplexContentExtension:
             this.complexContentExtension = (XmlSchemaComplexContentExtension)container;
             break;
         case State.ComplexContentRestriction:
             this.complexContentRestriction = (XmlSchemaComplexContentRestriction)container;
             break;
         case State.SimpleContent:
             this.simpleContent = (XmlSchemaSimpleContent)container;
             break;
         case State.SimpleContentExtension:
             this.simpleContentExtension = (XmlSchemaSimpleContentExtension)container;
             break;
         case State.SimpleContentRestriction:
             this.simpleContentRestriction = (XmlSchemaSimpleContentRestriction)container;
             break;
         case State.SimpleTypeUnion:
             this.simpleTypeUnion = (XmlSchemaSimpleTypeUnion)container;
             break;
         case State.SimpleTypeList:
             this.simpleTypeList = (XmlSchemaSimpleTypeList)container;
             break;
         case State.SimpleTypeRestriction:
             this.simpleTypeRestriction = (XmlSchemaSimpleTypeRestriction)container;
             break;
         case State.Unique:
         case State.Key:
         case State.KeyRef:
             this.identityConstraint = (XmlSchemaIdentityConstraint)container;
             break;
         case State.Selector:
         case State.Field:
             this.xpath = (XmlSchemaXPath)container;
             break;
         case State.MinExclusive:
         case State.MinInclusive:
         case State.MaxExclusive:
         case State.MaxInclusive:
         case State.TotalDigits:
         case State.FractionDigits:
         case State.Length:
         case State.MinLength:
         case State.MaxLength:
         case State.Enumeration:
         case State.Pattern:
         case State.WhiteSpace:
             this.facet = (XmlSchemaFacet)container;
             break;
         case State.AppInfo:
             this.appInfo = (XmlSchemaAppInfo)container;
             break;
         case State.Documentation:
             this.documentation = (XmlSchemaDocumentation)container;
             break;
         case State.Redefine:
             this.redefine = (XmlSchemaRedefine)container;
             break;
         default:
             Debug.Assert(false, "State is " + state);
             break;
     }
 }
コード例 #36
0
ファイル: xsd.cs プロジェクト: ArildF/masters
        private static void AddElementAndType(XmlSchema schema, string baseXsdType, string ns) {
            // name the element and soap-encoding type the same as the base XSD type
            XmlSchemaElement el = new XmlSchemaElement();
            el.Name = baseXsdType;
            el.SchemaTypeName = new XmlQualifiedName(baseXsdType, ns);
            schema.Items.Add(el);

            XmlSchemaComplexType type = new XmlSchemaComplexType();
            type.Name = baseXsdType;
            XmlSchemaSimpleContent model = new XmlSchemaSimpleContent();
            type.ContentModel = model;

            XmlSchemaSimpleContentExtension ex = new XmlSchemaSimpleContentExtension();
            ex.BaseTypeName = new XmlQualifiedName(baseXsdType, XmlSchema.Namespace);
            model.Content = ex;
            schema.Items.Add(type);
        }
 private void CompileSimpleContentExtension(XmlSchemaComplexType complexType, XmlSchemaSimpleContentExtension simpleExtension)
 {
     XmlSchemaComplexType redefined = null;
     if ((complexType.Redefined != null) && (simpleExtension.BaseTypeName == complexType.Redefined.QualifiedName))
     {
         redefined = (XmlSchemaComplexType) complexType.Redefined;
         this.CompileComplexType(redefined);
         complexType.SetBaseSchemaType(redefined);
         complexType.SetDatatype(redefined.Datatype);
     }
     else
     {
         XmlSchemaType anySchemaType = this.GetAnySchemaType(simpleExtension.BaseTypeName);
         if (anySchemaType == null)
         {
             base.SendValidationEvent("Sch_UndeclaredType", simpleExtension.BaseTypeName.ToString(), complexType);
         }
         else
         {
             complexType.SetBaseSchemaType(anySchemaType);
             complexType.SetDatatype(anySchemaType.Datatype);
         }
         redefined = anySchemaType as XmlSchemaComplexType;
     }
     if (redefined != null)
     {
         if ((redefined.FinalResolved & XmlSchemaDerivationMethod.Extension) != XmlSchemaDerivationMethod.Empty)
         {
             base.SendValidationEvent("Sch_BaseFinalExtension", complexType);
         }
         if (redefined.ContentType != XmlSchemaContentType.TextOnly)
         {
             base.SendValidationEvent("Sch_NotSimpleContent", complexType);
         }
     }
     complexType.SetDerivedBy(XmlSchemaDerivationMethod.Extension);
     this.CompileLocalAttributes(redefined, complexType, simpleExtension.Attributes, simpleExtension.AnyAttribute, XmlSchemaDerivationMethod.Extension);
 }
コード例 #38
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);
        }
コード例 #39
0
ファイル: infer.cs プロジェクト: krytht/DotNetReferenceSource
 private void MoveAttributes(XmlSchemaSimpleContentExtension scExtension,  XmlSchemaComplexType ct) {
     //copy all attributes from the simple content to the complex type
     //This is ok since when we move from complex type to simple content extension we copy from AttributeUses property
     for (int i = 0; i < scExtension.Attributes.Count; ++i)  //since simpleContent is being cleared
     {
         ct.Attributes.Add(scExtension.Attributes[i]);
     }
 }
コード例 #40
0
 XmlQualifiedName ExportStructMapping(StructMapping mapping, string ns, XmlSchemaElement element) {
     if (mapping.TypeDesc.IsRoot) {
         needToExportRoot = true;
         return XmlQualifiedName.Empty;
     }
     if (mapping.IsAnonymousType) {
         if (references[mapping] != null)
             throw new InvalidOperationException(Res.GetString(Res.XmlCircularReference2, mapping.TypeDesc.Name, "AnonymousType", "false"));
         references[mapping] = mapping;
     }
     XmlSchemaComplexType type = (XmlSchemaComplexType)types[mapping];
     if (type == null) {
         if (!mapping.IncludeInSchema) throw new InvalidOperationException(Res.GetString(Res.XmlCannotIncludeInSchema, mapping.TypeDesc.Name));
         CheckForDuplicateType(mapping, mapping.Namespace);
         type = new XmlSchemaComplexType();
         if (!mapping.IsAnonymousType) {
             type.Name = mapping.TypeName;
             AddSchemaItem(type, mapping.Namespace, ns);
             types.Add(mapping, type);
         }
         type.IsAbstract = mapping.TypeDesc.IsAbstract;
         bool openModel = mapping.IsOpenModel;
         if (mapping.BaseMapping != null && mapping.BaseMapping.IncludeInSchema) {
             if (mapping.BaseMapping.IsAnonymousType) {
                 throw new InvalidOperationException(Res.GetString(Res.XmlAnonymousBaseType, mapping.TypeDesc.Name, mapping.BaseMapping.TypeDesc.Name, "AnonymousType", "false"));
             }
             if (mapping.HasSimpleContent) {
                 XmlSchemaSimpleContent model = new XmlSchemaSimpleContent();
                 XmlSchemaSimpleContentExtension extension = new XmlSchemaSimpleContentExtension();
                 extension.BaseTypeName = ExportStructMapping(mapping.BaseMapping, mapping.Namespace, null);
                 model.Content = extension;
                 type.ContentModel = model;
             }
             else {
                 XmlSchemaComplexContentExtension extension = new XmlSchemaComplexContentExtension();
                 extension.BaseTypeName = ExportStructMapping(mapping.BaseMapping, mapping.Namespace, null);
                 XmlSchemaComplexContent model = new XmlSchemaComplexContent();
                 model.Content = extension;
                 model.IsMixed = XmlSchemaImporter.IsMixed((XmlSchemaComplexType)types[mapping.BaseMapping]);
                 type.ContentModel = model;
             }
             openModel = false;
         }
         ExportTypeMembers(type, mapping.Members, mapping.TypeName, mapping.Namespace, mapping.HasSimpleContent, openModel);
         ExportDerivedMappings(mapping);
         if (mapping.XmlnsMember != null) {
             AddXmlnsAnnotation(type, mapping.XmlnsMember.Name);
         }
     }
     else {
         AddSchemaImport(mapping.Namespace, ns);
     }
     if (mapping.IsAnonymousType) {
         references[mapping] = null;
         if (element != null) 
             element.SchemaType = type;
         return XmlQualifiedName.Empty;
     }
     else {
         XmlQualifiedName qname = new XmlQualifiedName(type.Name, mapping.Namespace);
         if (element != null) element.SchemaTypeName = qname;
         return qname;
     }
 }
コード例 #41
0
ファイル: infer.cs プロジェクト: krytht/DotNetReferenceSource
            /// <summary>
            /// Sets type of the xse based on the currently read element.
            /// If the type is already set, verifies that it matches the instance and if not, updates the type to validate the instance.
            /// </summary>
            /// <param name="xse">XmlSchemaElement corresponding to the element just read by the xtr XmlTextReader</param>
            /// <param name="bCreatingNewType">true if the type is newly created, false if the type already existed and matches the current element name</param>
            /// <param name="nsContext">namespaceURI of the parent element. Used to distinguish if ref= should be used when parent is in different ns than child.</param>
            internal void InferElement(XmlSchemaElement xse, bool bCreatingNewType, XmlSchema parentSchema)
            {
            
                bool bEmptyElement = xtr.IsEmptyElement;
                int lastUsedSeqItem = -1;

                Hashtable table = new Hashtable();
                XmlSchemaType schemaType = GetEffectiveSchemaType(xse, bCreatingNewType);
                XmlSchemaComplexType ct = schemaType as XmlSchemaComplexType;

                //infer type based on content of the current element
                if (xtr.MoveToFirstAttribute())
                {
                    ProcessAttributes(ref xse, schemaType, bCreatingNewType, parentSchema);
                }
                else
                {
                    if (!bCreatingNewType && ct != null) 
                    {   //if type already exists and can potentially have attributes
                        MakeExistingAttributesOptional(ct, null);
                    }
                }
                if (ct == null || ct == XmlSchemaComplexType.AnyType) { //It was null or simple type, after processing attributes, this might have been set
                    ct = xse.SchemaType as XmlSchemaComplexType;
                }
                //xse's type is set either to complex type if attributes exist or null
                if (bEmptyElement)  //<element attr="3232" />
                {
                    if (!bCreatingNewType)
                    {
                        if (null != ct)
                        {
                            if (null!= ct.Particle )

                            {
                                ct.Particle.MinOccurs = 0;
                            }
                            else if (null != ct.ContentModel)
                            {
                                XmlSchemaSimpleContentExtension sce = CheckSimpleContentExtension(ct);
                                sce.BaseTypeName = ST_string;
                                sce.LineNumber = TF_string;
                            }
                        }
                        else if (!xse.SchemaTypeName.IsEmpty)
                        {
                            xse.LineNumber = TF_string;
                            xse.SchemaTypeName = ST_string;
                        }
                    }
                    else
                    {
                        xse.LineNumber = TF_string;
                        //xse.SchemaTypeName = ST_string; //My change
                    }
                    return; //We are done processing this element - all attributes are already added
                }
                bool bWhiteSpace = false;
                do
                { 
                    xtr.Read();
                    if (xtr.NodeType == XmlNodeType.Whitespace) 
                    {
                        bWhiteSpace = true;
                    }
                    if (xtr.NodeType == XmlNodeType.EntityReference) 
                    {
                        throw new XmlSchemaInferenceException(Res.SchInf_entity, 0, 0);
                    }
                } while( (!xtr.EOF) && (xtr.NodeType != XmlNodeType.EndElement) && (xtr.NodeType != XmlNodeType.CDATA)&&(xtr.NodeType != XmlNodeType.Element)&&(xtr.NodeType != XmlNodeType.Text) );

                if (xtr.NodeType == XmlNodeType.EndElement)
                {
                    if (bWhiteSpace) {
                        if (ct != null)
                        {
                            if (null != ct.ContentModel)
                            {
                                XmlSchemaSimpleContentExtension sce = CheckSimpleContentExtension(ct);
                                sce.BaseTypeName = ST_string;
                                sce.LineNumber = TF_string;
                            }
                            else if (bCreatingNewType)
                            {
                                //attributes exist, but both Particle and ContentModel == null - this must be complex type with simpleContent extension
                                XmlSchemaSimpleContent sc = new XmlSchemaSimpleContent();
                                ct.ContentModel = sc;
                                XmlSchemaSimpleContentExtension sce = new XmlSchemaSimpleContentExtension();
                                sc.Content = sce;

                                MoveAttributes(ct, sce, bCreatingNewType);
                                
                                sce.BaseTypeName = ST_string;
                                sce.LineNumber = TF_string;
                            }
                            else
                                ct.IsMixed = true;
                        } 
                        else
                        {
                            xse.SchemaTypeName = ST_string;
                            xse.LineNumber = TF_string;
                        }
                    }
                    if (bCreatingNewType) 
                    {
                        xse.LineNumber = TF_string;
                        //xse.SchemaTypeName = ST_string; //my change
                    }
                    else
                    {
                        if (null != ct)
                        {
                            if (null!= ct.Particle) 
                            {
                                ct.Particle.MinOccurs = 0;
                            }
                            else if (null != ct.ContentModel)
                            {
                                XmlSchemaSimpleContentExtension sce = CheckSimpleContentExtension(ct);
                                sce.BaseTypeName = ST_string;
                                sce.LineNumber = TF_string;
                            }
                        }
                        else if (!xse.SchemaTypeName.IsEmpty)
                        {
                            xse.LineNumber = TF_string;
                            xse.SchemaTypeName = ST_string;
                        }
                    }

                    return; //<element attr="232"></element>
                }
                int iChildNumber = 0;
                bool bCreatingNewSequence = false;
                while (!xtr.EOF && (xtr.NodeType != XmlNodeType.EndElement))
                {
                    bool bNextNodeAlreadyRead = false;  //In some cases we have to look ahead one node. If true means that we did look ahead.
                    iChildNumber++;
                    if ((xtr.NodeType == XmlNodeType.Text) || (xtr.NodeType == XmlNodeType.CDATA) ) //node can be simple type, complex with simple content or complex with mixed content
                    {
                        if (null != ct)
                        {
                            if (null != ct.Particle)
                            {
                                ct.IsMixed = true;
                                if (iChildNumber==1)
                                {
                                    //if this is the only child and other elements do not follow, we must set particle minOccurs="0"
                                    do{ xtr.Read();} while( (!xtr.EOF) && ((xtr.NodeType == XmlNodeType.CDATA)||(xtr.NodeType == XmlNodeType.Text) ||  (xtr.NodeType == XmlNodeType.Comment) || (xtr.NodeType == XmlNodeType.ProcessingInstruction) || (xtr.NodeType == XmlNodeType.Whitespace) || (xtr.NodeType == XmlNodeType.SignificantWhitespace) || (xtr.NodeType == XmlNodeType.XmlDeclaration)));
                                    bNextNodeAlreadyRead = true;
                                    if (xtr.NodeType == XmlNodeType.EndElement)
                                        ct.Particle.MinOccurs=decimal.Zero;
                                }
                            }
                            else if (null!=ct.ContentModel)
                            {   //complexType with simpleContent
                                XmlSchemaSimpleContentExtension sce = CheckSimpleContentExtension(ct);
                                if ((xtr.NodeType == XmlNodeType.Text) && (iChildNumber==1))
                                {
                                    int SimpleType = -1;
                                    if (xse.Parent == null)
                                    {
                                        SimpleType = sce.LineNumber; // we use LineNumber to represent valid type flags
                                    }
                                    else
                                    {
                                        SimpleType = GetSchemaType(sce.BaseTypeName);
                                        xse.Parent = null;
                                    }
                                    sce.BaseTypeName = RefineSimpleType(xtr.Value, ref SimpleType);
                                    sce.LineNumber = SimpleType; // we use LineNumber to represent valid type flags
                                }
                                else
                                {
                                    sce.BaseTypeName = ST_string;
                                    sce.LineNumber = TF_string;
                                }
                            }
                            else
                            {
                                //attributes exist, but both Particle and ContentModel == null - this must be complex type with simpleContent extension
                                XmlSchemaSimpleContent sc = new XmlSchemaSimpleContent();
                                ct.ContentModel = sc;
                                XmlSchemaSimpleContentExtension sce = new XmlSchemaSimpleContentExtension();
                                sc.Content = sce;

                                MoveAttributes(ct, sce, bCreatingNewType);

                                if (xtr.NodeType == XmlNodeType.Text)
                                {
                                    int TypeFlags;
                                    if(!bCreatingNewType)
                                        //previously this was empty element
                                        TypeFlags=TF_string;
                                    else
                                        TypeFlags = -1;
                                    sce.BaseTypeName = RefineSimpleType(xtr.Value, ref TypeFlags);
                                    sce.LineNumber = TypeFlags; // we use LineNumber to store flags of valid types
                                }
                                else
                                {
                                    sce.BaseTypeName = ST_string;
                                    sce.LineNumber = TF_string;
                                }
                                
                            }
                        }
                        else
                        {   //node is currently empty or with SimpleType
                            //node will become simple type
                            if (iChildNumber>1)
                            {
                                //more than one consecutive text nodes probably with PI in between
                                xse.SchemaTypeName = ST_string;
                                xse.LineNumber = TF_string;// we use LineNumber to store flags of valid types
                            }
                            else
                            {
                                int TypeFlags = -1;
                                if (bCreatingNewType)
                                    if (xtr.NodeType == XmlNodeType.Text)
                                    {
                                        xse.SchemaTypeName = RefineSimpleType(xtr.Value, ref TypeFlags);
                                        xse.LineNumber = TypeFlags; // we use LineNumber to store flags of valid types
                                    }
                                    else
                                    {
                                        xse.SchemaTypeName = ST_string;
                                        xse.LineNumber = TF_string;// we use LineNumber to store flags of valid types
                                    }
                                else if (xtr.NodeType == XmlNodeType.Text)
                                {
                                    if (xse.Parent == null)
                                    {
                                        TypeFlags = xse.LineNumber;
                                    }
                                    else
                                    {
                                        TypeFlags = GetSchemaType(xse.SchemaTypeName);
                                        if (TypeFlags == -1 && xse.LineNumber == TF_string) { //Since schemaTypeName is not set for empty elements (<e></e>)
                                            TypeFlags = TF_string;
                                        }
                                        xse.Parent = null;
                                    }
                                    xse.SchemaTypeName = RefineSimpleType(xtr.Value, ref TypeFlags);    //simple type
                                    xse.LineNumber = TypeFlags; // we use LineNumber to store flags of valid types
                                }
                                else
                                {
                                    xse.SchemaTypeName = ST_string;
                                    xse.LineNumber = TF_string;// we use LineNumber to store flags of valid types
                                }
                            }
                        } 
                    }
                    else if (xtr.NodeType == XmlNodeType.Element)
                    {
                        XmlQualifiedName qname = new XmlQualifiedName(xtr.LocalName, xtr.NamespaceURI);
                        bool Maxoccursflag = false;
                        if (table.Contains(qname)) 
                        {
                            Maxoccursflag = true;
                        }
                        else 
                        {
                            table.Add(qname, null);
                        }
                        if (ct==null)
                        { //untill now the element was empty or SimpleType - it now becomes complex type
                            ct = new XmlSchemaComplexType();
                            xse.SchemaType = ct;
                            if (!xse.SchemaTypeName.IsEmpty) //
                            {
                                ct.IsMixed=true;
                                xse.SchemaTypeName = XmlQualifiedName.Empty;
                            }
                        }
                        if (ct.ContentModel !=null)
                        {   //type was previously identified as simple content extension - we need to convert it to sequence
                            XmlSchemaSimpleContentExtension sce = CheckSimpleContentExtension(ct);
                            MoveAttributes(sce, ct);
                            ct.ContentModel = null;
                            ct.IsMixed = true;
                            if (ct.Particle != null)
                                throw new XmlSchemaInferenceException(Res.SchInf_particle, 0, 0);
                            ct.Particle = new XmlSchemaSequence();
                            bCreatingNewSequence = true;
                            XmlSchemaElement subelement = AddElement(xtr.LocalName, xtr.Prefix, xtr.NamespaceURI, parentSchema,((XmlSchemaSequence)ct.Particle).Items, -1);
                            lastUsedSeqItem = 0;
                            if (!bCreatingNewType)
                                ct.Particle.MinOccurs=0;    //previously this was simple type so subelements did not exist
                        }
                        else if (ct.Particle == null)
                        {
                            ct.Particle = new XmlSchemaSequence();
                            bCreatingNewSequence = true;
                            XmlSchemaElement subelement = AddElement(xtr.LocalName, xtr.Prefix, xtr.NamespaceURI, parentSchema,((XmlSchemaSequence)ct.Particle).Items, -1);
                            if (!bCreatingNewType)
                            {
                                ((XmlSchemaSequence)ct.Particle).MinOccurs = decimal.Zero;
                                //  subelement.MinOccurs = decimal.Zero;
                            }
                    
                            lastUsedSeqItem = 0;
                        }
                        else
                        {
                            bool bParticleChanged = false;
                            XmlSchemaElement subelement = FindMatchingElement(bCreatingNewType || bCreatingNewSequence, xtr, ct, ref lastUsedSeqItem, ref bParticleChanged, parentSchema, Maxoccursflag);
                        }
                    }
                    else if (xtr.NodeType == XmlNodeType.Text)
                    {
                        if (ct==null)
                            throw new XmlSchemaInferenceException(Res.SchInf_ct, 0, 0);
                        ct.IsMixed = true;
                    }
                    do
                    { 
                        if (xtr.NodeType == XmlNodeType.EntityReference)
                        {
                            throw new XmlSchemaInferenceException(Res.SchInf_entity, 0, 0);

                        }
                        if (!bNextNodeAlreadyRead)
                        {
                            xtr.Read();
                        }
                        else
                        {
                            bNextNodeAlreadyRead = false;
                        }
                    } while( (!xtr.EOF) && (xtr.NodeType != XmlNodeType.EndElement) && (xtr.NodeType != XmlNodeType.CDATA)&&(xtr.NodeType != XmlNodeType.Element)&&(xtr.NodeType != XmlNodeType.Text));
                }
                if (lastUsedSeqItem != -1)
                {
                    //Verify if all elements in a sequence exist, if not set MinOccurs=0
                    while (++lastUsedSeqItem < ((XmlSchemaSequence)ct.Particle).Items.Count)
                    {
                        if (((XmlSchemaSequence)ct.Particle).Items[lastUsedSeqItem].GetType() != typeof (XmlSchemaElement))
                            throw new XmlSchemaInferenceException(Res.SchInf_seq, 0 , 0);
                        XmlSchemaElement subElement = (XmlSchemaElement) ((XmlSchemaSequence)ct.Particle).Items[lastUsedSeqItem];
                        subElement.MinOccurs = 0;
                    }
                }

            }   
コード例 #42
0
        //<simpleContent
        //  id = ID
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?, (restriction | extension))
        //</simpleContent>
        internal static XmlSchemaSimpleContent Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaSimpleContent simple = new XmlSchemaSimpleContent();

            reader.MoveToElement();

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

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

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

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(simple);
            }
            //Content: (annotation?, (restriction | extension))
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaSimpleContent.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (level <= 1 && reader.LocalName == "annotation")
                {
                    level = 2; //Only one annotation
                    XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h);
                    if (annotation != null)
                    {
                        simple.Annotation = annotation;
                    }
                    continue;
                }
                if (level <= 2)
                {
                    if (reader.LocalName == "restriction")
                    {
                        level = 3;
                        XmlSchemaSimpleContentRestriction restriction = XmlSchemaSimpleContentRestriction.Read(reader, h);
                        if (restriction != null)
                        {
                            simple.content = restriction;
                        }
                        continue;
                    }
                    if (reader.LocalName == "extension")
                    {
                        level = 3;
                        XmlSchemaSimpleContentExtension extension = XmlSchemaSimpleContentExtension.Read(reader, h);
                        if (extension != null)
                        {
                            simple.content = extension;
                        }
                        continue;
                    }
                }
                reader.RaiseInvalidElementError();
            }
            return(simple);
        }