Summary description for XmlSchemaSimpleTypeList.
Inheritance: XmlSchemaSimpleTypeContent
        protected override void Visit(XmlSchemaSimpleTypeList list)
        {
            PushNode(SimpleTypeStructureNodeType.List, list);

            Traverse(list.BaseItemType);

            PopNode();
        }
Beispiel #2
0
        static XmlSchemaSimpleType()
        {
            // This is not used in the meantime.
            XmlSchemaSimpleType     st   = new XmlSchemaSimpleType();
            XmlSchemaSimpleTypeList list = new XmlSchemaSimpleTypeList();

            list.ItemTypeName            = new XmlQualifiedName("anyURI", XmlSchema.Namespace);
            st.Content                   = list;
            st.BaseXmlSchemaTypeInternal = null;
            st.variety                   = XmlSchemaDerivationMethod.List;
            schemaLocationType           = st;

            // Built-In schema types
            XsAnySimpleType = BuildSchemaType("anySimpleType", null);
            XsString        = BuildSchemaType("string", "anySimpleType");
            XsBoolean       = BuildSchemaType("boolean", "anySimpleType");
            XsDecimal       = BuildSchemaType("decimal", "anySimpleType");
            XsFloat         = BuildSchemaType("float", "anySimpleType");
            XsDouble        = BuildSchemaType("double", "anySimpleType");
            XsDuration      = BuildSchemaType("duration", "anySimpleType");
            XsDateTime      = BuildSchemaType("dateTime", "anySimpleType");
            XsTime          = BuildSchemaType("time", "anySimpleType");
            XsDate          = BuildSchemaType("date", "anySimpleType");
            XsGYearMonth    = BuildSchemaType("gYearMonth", "anySimpleType");
            XsGYear         = BuildSchemaType("gYear", "anySimpleType");
            XsGMonthDay     = BuildSchemaType("gMonthDay", "anySimpleType");
            XsGDay          = BuildSchemaType("gDay", "anySimpleType");
            XsGMonth        = BuildSchemaType("gMonth", "anySimpleType");
            XsHexBinary     = BuildSchemaType("hexBinary", "anySimpleType");
            XsBase64Binary  = BuildSchemaType("base64Binary", "anySimpleType");
            XsAnyUri        = BuildSchemaType("anyURI", "anySimpleType");
            XsQName         = BuildSchemaType("QName", "anySimpleType");
            XsNotation      = BuildSchemaType("NOTATION", "anySimpleType");
            // derived types
            XsNormalizedString = BuildSchemaType("normalizedString", "string");
            XsToken            = BuildSchemaType("token", "normalizedString");
            XsLanguage         = BuildSchemaType("language", "token");
            XsNMToken          = BuildSchemaType("NMTOKEN", "token");
            XsName             = BuildSchemaType("Name", "token");
            XsNCName           = BuildSchemaType("NCName", "Name");

            XsID     = BuildSchemaType("ID", "NCName");
            XsIDRef  = BuildSchemaType("IDREF", "NCName");
            XsEntity = BuildSchemaType("ENTITY", "NCName");

            XsInteger            = BuildSchemaType("integer", "decimal");
            XsNonPositiveInteger = BuildSchemaType("nonPositiveInteger", "integer");
            XsNegativeInteger    = BuildSchemaType("negativeInteger", "nonPositiveInteger");
            XsLong  = BuildSchemaType("long", "integer");
            XsInt   = BuildSchemaType("int", "long");
            XsShort = BuildSchemaType("short", "int");
            XsByte  = BuildSchemaType("byte", "short");
            XsNonNegativeInteger = BuildSchemaType("nonNegativeInteger", "integer");
            XsUnsignedLong       = BuildSchemaType("unsignedLong", "nonNegativeInteger");
            XsUnsignedInt        = BuildSchemaType("unsignedInt", "unsignedLong");
            XsUnsignedShort      = BuildSchemaType("unsignedShort", "unsignedInt");
            XsUnsignedByte       = BuildSchemaType("unsignedByte", "unsignedShort");
            XsPositiveInteger    = BuildSchemaType("positiveInteger", "nonNegativeInteger");

            // xdt:*
            XdtAnyAtomicType     = BuildSchemaType("anyAtomicType", "anySimpleType", true, false);
            XdtUntypedAtomic     = BuildSchemaType("untypedAtomic", "anyAtomicType", true, true);
            XdtDayTimeDuration   = BuildSchemaType("dayTimeDuration", "duration", true, false);
            XdtYearMonthDuration = BuildSchemaType("yearMonthDuration", "duration", true, false);

            // NMTOKENS, IDREFS, ENTITIES - lists
            XsIDRefs = new XmlSchemaSimpleType();
            XmlSchemaSimpleTypeList sl = new XmlSchemaSimpleTypeList();

            sl.ItemType      = XsIDRef;
            XsIDRefs.Content = sl;
            XsEntities       = new XmlSchemaSimpleType();
            sl                 = new XmlSchemaSimpleTypeList();
            sl.ItemType        = XsEntity;
            XsEntities.Content = sl;
            XsNMTokens         = new XmlSchemaSimpleType();
            sl                 = new XmlSchemaSimpleTypeList();
            sl.ItemType        = XsNMToken;
            XsNMTokens.Content = sl;
        }
        static void AddUriListType(DiscoveryVersion discoveryVersion, XmlSchema schema)
        {
            // <xs:simpleType name="UriListType">
            XmlSchemaSimpleType uriListType = new XmlSchemaSimpleType();
            uriListType.Name = ProtocolStrings.SchemaNames.UriListType;

            // <xs:list itemType="xs:anyURI" /> 
            XmlSchemaSimpleTypeList uriListTypeContent = new XmlSchemaSimpleTypeList();
            uriListTypeContent.ItemTypeName = discoveryVersion.Implementation.QualifiedNames.AnyUriType;

            // </xs:simpleType>
            uriListType.Content = uriListTypeContent;

            schema.Items.Add(uriListType);
        }
        void ExportAttributeAccessor(XmlSchemaComplexType type, AttributeAccessor accessor, bool valueTypeOptional, string ns) {
            if (accessor == null) return;
            XmlSchemaObjectCollection attributes;

            if (type.ContentModel != null) {
                if (type.ContentModel.Content is XmlSchemaComplexContentRestriction)
                    attributes = ((XmlSchemaComplexContentRestriction)type.ContentModel.Content).Attributes;
                else if (type.ContentModel.Content is XmlSchemaComplexContentExtension)
                    attributes = ((XmlSchemaComplexContentExtension)type.ContentModel.Content).Attributes;
                else if (type.ContentModel.Content is XmlSchemaSimpleContentExtension)
                    attributes = ((XmlSchemaSimpleContentExtension)type.ContentModel.Content).Attributes;
                else
                    throw new InvalidOperationException(Res.GetString(Res.XmlInvalidContent, type.ContentModel.Content.GetType().Name));
            }
            else {
                attributes = type.Attributes;
            }

            if (accessor.IsSpecialXmlNamespace) {

                // add <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
                AddSchemaImport(XmlReservedNs.NsXml, ns);

                // generate <xsd:attribute ref="xml:lang" use="optional" />
                XmlSchemaAttribute attribute = new XmlSchemaAttribute();
                attribute.Use = XmlSchemaUse.Optional;
                attribute.RefName = new XmlQualifiedName(accessor.Name, XmlReservedNs.NsXml);
                attributes.Add(attribute);
            }
            else if (accessor.Any) {
                if (type.ContentModel == null) {
                    type.AnyAttribute = new XmlSchemaAnyAttribute();
                }
                else {
                    XmlSchemaContent content = type.ContentModel.Content;
                    if (content is XmlSchemaComplexContentExtension) {
                        XmlSchemaComplexContentExtension extension = (XmlSchemaComplexContentExtension)content;
                        extension.AnyAttribute = new XmlSchemaAnyAttribute();
                    }
                    else if (content is XmlSchemaComplexContentRestriction) {
                        XmlSchemaComplexContentRestriction restriction = (XmlSchemaComplexContentRestriction)content;
                        restriction.AnyAttribute = new XmlSchemaAnyAttribute();
                    }
                    else if (type.ContentModel.Content is XmlSchemaSimpleContentExtension) {
                        XmlSchemaSimpleContentExtension extension = (XmlSchemaSimpleContentExtension)content;
                        extension.AnyAttribute = new XmlSchemaAnyAttribute();
                    }
                }
            }
            else {
                XmlSchemaAttribute attribute = new XmlSchemaAttribute();
                attribute.Use = XmlSchemaUse.None;
                if (!accessor.HasDefault && !valueTypeOptional && accessor.Mapping.TypeDesc.IsValueType) {
                    attribute.Use = XmlSchemaUse.Required;
                }
                attribute.Name = accessor.Name;
                if (accessor.Namespace == null || accessor.Namespace == ns) {
                    // determine the form attribute value
                    XmlSchema schema = schemas[ns];
                    if (schema == null)
                        attribute.Form = accessor.Form == attributeFormDefault ? XmlSchemaForm.None : accessor.Form;
                    else {
                        attribute.Form = accessor.Form == schema.AttributeFormDefault ? XmlSchemaForm.None : accessor.Form;
                    }
                    attributes.Add(attribute);
                }
                else {
                    // we are going to add the attribute to the top-level items. "use" attribute should not be set
                    if (this.attributes[accessor] == null) {
                        attribute.Use = XmlSchemaUse.None;
                        attribute.Form = accessor.Form;
                        AddSchemaItem(attribute, accessor.Namespace, ns);
                        this.attributes.Add(accessor, accessor);
                    }
                    XmlSchemaAttribute refAttribute = new XmlSchemaAttribute();
                    refAttribute.Use = XmlSchemaUse.None;
                    refAttribute.RefName = new XmlQualifiedName(accessor.Name, accessor.Namespace);
                    attributes.Add(refAttribute);
                    AddSchemaImport(accessor.Namespace, ns);
                }
                if (accessor.Mapping is PrimitiveMapping) {
                    PrimitiveMapping pm = (PrimitiveMapping)accessor.Mapping;
                    if (pm.IsList) {
                        // create local simple type for the list-like attributes
                        XmlSchemaSimpleType dataType = new XmlSchemaSimpleType();
                        XmlSchemaSimpleTypeList list = new XmlSchemaSimpleTypeList();
                        if (pm.IsAnonymousType) {
                            list.ItemType = (XmlSchemaSimpleType)ExportAnonymousPrimitiveMapping(pm);
                        }
                        else {
                            list.ItemTypeName = ExportPrimitiveMapping(pm, accessor.Namespace == null ? ns : accessor.Namespace);
                        }
                        dataType.Content = list;
                        attribute.SchemaType = dataType;
                    }
                    else {
                        if (pm.IsAnonymousType) {
                            attribute.SchemaType = (XmlSchemaSimpleType)ExportAnonymousPrimitiveMapping(pm);
                        }
                        else {
                            attribute.SchemaTypeName = ExportPrimitiveMapping(pm, accessor.Namespace == null ? ns : accessor.Namespace);
                        }
                    }
                }
                else if (!(accessor.Mapping is SpecialMapping))
                    throw new InvalidOperationException(Res.GetString(Res.XmlInternalError));

                if (accessor.HasDefault) {
                    attribute.DefaultValue = ExportDefaultValue(accessor.Mapping, accessor.Default);
                }
            }
        }
		void GetAttributeValueCompletionData (XmlCompletionDataList data, XmlSchemaSimpleTypeList list)
		{
			if (list.ItemType != null) {
				GetAttributeValueCompletionData (data, list.ItemType);
			} else if (list.ItemTypeName != null) {
				var simpleType = FindSimpleType (list.ItemTypeName);
				if (simpleType != null)
					GetAttributeValueCompletionData (data, simpleType);
			}
		}	
Beispiel #6
0
		XmlSchemaSimpleType GetSchemaSimpleListType (TypeData typeData)
		{
			XmlSchemaSimpleType stype = new XmlSchemaSimpleType ();
			XmlSchemaSimpleTypeList list = new XmlSchemaSimpleTypeList ();
			TypeData itemTypeData = TypeTranslator.GetTypeData (typeData.ListItemType);
			list.ItemTypeName = new XmlQualifiedName (itemTypeData.XmlType, XmlSchema.Namespace);
			stype.Content = list;
			return stype;
		}
		//<list 
		//  id = ID 
		//  itemType = QName 
		//  {any attributes with non-schema namespace . . .}>
		//  Content: (annotation?, (simpleType?))
		//</list>
		internal static XmlSchemaSimpleTypeList Read(XmlSchemaReader reader, ValidationEventHandler h)
		{
			XmlSchemaSimpleTypeList list = new XmlSchemaSimpleTypeList();
			reader.MoveToElement();

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

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

			while(reader.MoveToNextAttribute())
			{
				if(reader.Name == "id")
				{
					list.Id = reader.Value;
				}
				else if(reader.Name == "itemType")
				{
					Exception innerex;
					list.ItemTypeName = XmlSchemaUtil.ReadQNameAttribute(reader,out innerex);
					if(innerex != null)
						error(h, reader.Value + " is not a valid value for itemType attribute",innerex);
				}
				else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
				{
					error(h,reader.Name + " is not a valid attribute for list",null);
				}
				else
				{
					XmlSchemaUtil.ReadUnhandledAttribute(reader,list);
				}
			}
			
			reader.MoveToElement();
			if(reader.IsEmptyElement)
				return list;
			//  Content: annotation?, simpleType?
			int level = 1;
			while(reader.ReadNextElement())
			{
				if(reader.NodeType == XmlNodeType.EndElement)
				{
					if(reader.LocalName != xmlname)
						error(h,"Should not happen :2: XmlSchemaSimpleTypeList.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)
						list.Annotation = annotation;
					continue;
				}
				if(level <= 2 && reader.LocalName == "simpleType")
				{
					level = 3;
					XmlSchemaSimpleType stype = XmlSchemaSimpleType.Read(reader,h);
					if(stype != null)
						list.itemType = stype;
					continue;
				}
				reader.RaiseInvalidElementError();
			}
			return list;
		}
        /// <summary>
        /// Finish constructing built-in types by setting up derivation and list links.
        /// </summary>
        internal static void FinishBuiltinType(XmlSchemaSimpleType derivedType, XmlSchemaSimpleType baseType) {
            Debug.Assert(derivedType != null && baseType != null);

            // Create link from the derived type to the base type
            derivedType.SetBaseSchemaType(baseType);
            derivedType.SetDerivedBy(XmlSchemaDerivationMethod.Restriction);
            if (derivedType.Datatype.Variety == XmlSchemaDatatypeVariety.Atomic) { //Content is restriction
                XmlSchemaSimpleTypeRestriction restContent = new XmlSchemaSimpleTypeRestriction();
                restContent.BaseTypeName = baseType.QualifiedName;
                derivedType.Content = restContent;
            }

            // Create link from a list type to its member type
            if (derivedType.Datatype.Variety == XmlSchemaDatatypeVariety.List) {
                XmlSchemaSimpleTypeList listContent = new XmlSchemaSimpleTypeList();
                derivedType.SetDerivedBy(XmlSchemaDerivationMethod.List);
                switch (derivedType.Datatype.TypeCode) {
                    case XmlTypeCode.NmToken:
                        listContent.ItemType = listContent.BaseItemType = enumToTypeCode[(int) XmlTypeCode.NmToken];
                        break;

                    case XmlTypeCode.Entity:
                        listContent.ItemType = listContent.BaseItemType = enumToTypeCode[(int) XmlTypeCode.Entity];
                        break;

                    case XmlTypeCode.Idref:
                        listContent.ItemType = listContent.BaseItemType = enumToTypeCode[(int) XmlTypeCode.Idref];
                        break;
                }
                derivedType.Content = listContent;
            }
        }
Beispiel #9
0
		static XmlSchemaSimpleType ()
		{
			// This is not used in the meantime.
			XmlSchemaSimpleType st = new XmlSchemaSimpleType ();
			XmlSchemaSimpleTypeList list = new XmlSchemaSimpleTypeList ();
			list.ItemTypeName = new XmlQualifiedName ("anyURI", XmlSchema.Namespace);
			st.Content = list;
			st.BaseXmlSchemaTypeInternal = null;
			st.variety = XmlSchemaDerivationMethod.List;
			schemaLocationType = st;

#if NET_2_0
			// Built-In schema types
			XsAnySimpleType = BuildSchemaType ("anySimpleType", null);
			XsString = BuildSchemaType ("string", "anySimpleType");
			XsBoolean = BuildSchemaType ("boolean", "anySimpleType");
			XsDecimal = BuildSchemaType ("decimal", "anySimpleType");
			XsFloat = BuildSchemaType ("float", "anySimpleType");
			XsDouble = BuildSchemaType ("double", "anySimpleType");
			XsDuration = BuildSchemaType ("duration", "anySimpleType");
			XsDateTime = BuildSchemaType ("dateTime", "anySimpleType");
			XsTime = BuildSchemaType ("time", "anySimpleType");
			XsDate = BuildSchemaType ("date", "anySimpleType");
			XsGYearMonth = BuildSchemaType ("gYearMonth", "anySimpleType");
			XsGYear = BuildSchemaType ("gYear", "anySimpleType");
			XsGMonthDay = BuildSchemaType ("gMonthDay", "anySimpleType");
			XsGDay = BuildSchemaType ("gDay", "anySimpleType");
			XsGMonth = BuildSchemaType ("gMonth", "anySimpleType");
			XsHexBinary = BuildSchemaType ("hexBinary", "anySimpleType");
			XsBase64Binary = BuildSchemaType ("base64Binary", "anySimpleType");
			XsAnyUri = BuildSchemaType ("anyURI", "anySimpleType");
			XsQName = BuildSchemaType ("QName", "anySimpleType");
			XsNotation = BuildSchemaType ("NOTATION", "anySimpleType");
			// derived types
			XsNormalizedString = BuildSchemaType ("normalizedString", "string");
			XsToken = BuildSchemaType ("token", "normalizedString");
			XsLanguage = BuildSchemaType ("language", "token");
			XsNMToken = BuildSchemaType ("NMTOKEN", "token");
			XsName = BuildSchemaType ("Name", "token");
			XsNCName = BuildSchemaType ("NCName", "Name");

			XsID = BuildSchemaType ("ID", "NCName");
			XsIDRef = BuildSchemaType ("IDREF", "NCName");
			XsEntity = BuildSchemaType ("ENTITY", "NCName");

			XsInteger = BuildSchemaType ("integer", "decimal");
			XsNonPositiveInteger = BuildSchemaType ("nonPositiveInteger", "integer");
			XsNegativeInteger = BuildSchemaType ("negativeInteger", "nonPositiveInteger");
			XsLong = BuildSchemaType ("long", "integer");
			XsInt = BuildSchemaType ("int", "long");
			XsShort = BuildSchemaType ("short", "int");
			XsByte = BuildSchemaType ("byte", "short");
			XsNonNegativeInteger = BuildSchemaType ("nonNegativeInteger", "integer");
			XsUnsignedLong = BuildSchemaType ("unsignedLong", "nonNegativeInteger");
			XsUnsignedInt = BuildSchemaType ("unsignedInt", "unsignedLong");
			XsUnsignedShort = BuildSchemaType ("unsignedShort", "unsignedInt");
			XsUnsignedByte = BuildSchemaType ("unsignedByte", "unsignedShort");
			XsPositiveInteger = BuildSchemaType ("positiveInteger", "nonNegativeInteger");

			// xdt:*
			XdtAnyAtomicType = BuildSchemaType ("anyAtomicType", "anySimpleType", true, false);
			XdtUntypedAtomic = BuildSchemaType ("untypedAtomic", "anyAtomicType", true, true);
			XdtDayTimeDuration = BuildSchemaType ("dayTimeDuration", "duration", true, false);
			XdtYearMonthDuration = BuildSchemaType ("yearMonthDuration", "duration", true, false);

			// NMTOKENS, IDREFS, ENTITIES - lists
			XsIDRefs = new XmlSchemaSimpleType ();
			XmlSchemaSimpleTypeList sl = new XmlSchemaSimpleTypeList ();
			sl.ItemType = XsIDRef;
			XsIDRefs.Content = sl;
			XsEntities = new XmlSchemaSimpleType ();
			sl = new XmlSchemaSimpleTypeList ();
			sl.ItemType = XsEntity;
			XsEntities.Content = sl;
			XsNMTokens = new XmlSchemaSimpleType ();
			sl = new XmlSchemaSimpleTypeList ();
			sl.ItemType = XsNMToken;
			XsNMTokens.Content = sl;
#endif
		}
        /// <summary>
        /// Create and add an element to a service descriptions schema. Used to create a native XmlType element.
        /// </summary>
        /// <param name="elementName">A string contininig the name of an element.</param>
        /// <param name="elementTypeNs">A string containing the namespace of the type.</param>
        /// <param name="xmlTypeName">A string containing the name of an element type.</param>
        /// <param name="isArray">True if the element represents an array of native types.</param>
        /// <param name="serviceDesc">The ServiceDescription used to store Wsdl definition.</param>
        private void AddNativeTypeElement(string elementName, string elementNs, string xmlTypeName, bool isArray, XmlSchemaSequence seq, XmlSchema schema )
        {
            XmlSchemaElement elemType = new XmlSchemaElement();

            elemType.Name = elementName;
            if (isArray)
                elemType.SchemaTypeName = new XmlQualifiedName(elementName + "ListType", elementNs);
            else
                elemType.SchemaTypeName = new XmlQualifiedName(xmlTypeName, "http://www.w3.org/2001/XMLSchema");

            seq.Items.Add(elemType);

            // If this is an array add a simple list type
            if (isArray)
            {
                XmlSchemaSimpleType simpleType = new XmlSchemaSimpleType();
                simpleType.Name = elementName + "ListType";
                XmlSchemaSimpleTypeList simpleContent = new XmlSchemaSimpleTypeList();
                simpleContent.ItemTypeName = new XmlQualifiedName(xmlTypeName, "http://www.w3.org/2001/XMLSchema");
                simpleType.Content = simpleContent;
                AddSchemaItem(schema, simpleType);
            }
            return;
        }
Beispiel #11
0
 void Handler.BeginSimpleTypeList(XmlSchemaSimpleTypeList list)
 {
 }
 protected override void Visit(XmlSchemaSimpleTypeList list)
 {
     if (list.BaseItemType.QualifiedName.IsEmpty)
     {
         _writer.WriteHtmlArtItemWithText(ArtItem.List, "List");
     }
     else
     {
         var topic = _context.TopicManager.GetTopic(list.BaseItemType);
         if (topic != null)
         {
             _writer.WriteHtmlArtItemWithTopicLink(ArtItem.List, topic);
         }
         else
         {
             _writer.WriteHtmlArtItemWithText(ArtItem.List, list.BaseItemType.QualifiedName.Name);
         }
     }
 }
Beispiel #13
0
        internal static XmlSchemaSimpleTypeList Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaSimpleTypeList xmlSchemaSimpleTypeList = new XmlSchemaSimpleTypeList();

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

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != "list")
                    {
                        XmlSchemaObject.error(h, "Should not happen :2: XmlSchemaSimpleTypeList.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (num <= 1 && reader.LocalName == "annotation")
                {
                    num = 2;
                    XmlSchemaAnnotation xmlSchemaAnnotation = XmlSchemaAnnotation.Read(reader, h);
                    if (xmlSchemaAnnotation != null)
                    {
                        xmlSchemaSimpleTypeList.Annotation = xmlSchemaAnnotation;
                    }
                }
                else if (num <= 2 && reader.LocalName == "simpleType")
                {
                    num = 3;
                    XmlSchemaSimpleType xmlSchemaSimpleType = XmlSchemaSimpleType.Read(reader, h);
                    if (xmlSchemaSimpleType != null)
                    {
                        xmlSchemaSimpleTypeList.itemType = xmlSchemaSimpleType;
                    }
                }
                else
                {
                    reader.RaiseInvalidElementError();
                }
            }
            return(xmlSchemaSimpleTypeList);
        }
Beispiel #14
0
        //<simpleType
        //  final = (#all | (list | union | restriction))
        //  id = ID
        //  name = NCName
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?, (restriction | list | union))
        //</simpleType>
        internal static XmlSchemaSimpleType Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaSimpleType stype = new XmlSchemaSimpleType();

            reader.MoveToElement();

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

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

            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "final")
                {
                    Exception innerex;
                    stype.Final = XmlSchemaUtil.ReadDerivationAttribute(reader, out innerex, "final",
                                                                        XmlSchemaUtil.FinalAllowed);
                    if (innerex != null)
                    {
                        error(h, "some invalid values not a valid value for final", innerex);
                    }
                }
                else if (reader.Name == "id")
                {
                    stype.Id = reader.Value;
                }
                else if (reader.Name == "name")
                {
                    stype.Name = reader.Value;
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for simpleType", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, stype);
                }
            }

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

            //	Content: (annotation?, (restriction | list | union))
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaSimpleType.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)
                    {
                        stype.Annotation = annotation;
                    }
                    continue;
                }
                if (level <= 2)
                {
                    if (reader.LocalName == "restriction")
                    {
                        level = 3;
                        XmlSchemaSimpleTypeRestriction restriction = XmlSchemaSimpleTypeRestriction.Read(reader, h);
                        if (restriction != null)
                        {
                            stype.content = restriction;
                        }
                        continue;
                    }
                    if (reader.LocalName == "list")
                    {
                        level = 3;
                        XmlSchemaSimpleTypeList list = XmlSchemaSimpleTypeList.Read(reader, h);
                        if (list != null)
                        {
                            stype.content = list;
                        }
                        continue;
                    }
                    if (reader.LocalName == "union")
                    {
                        level = 3;
                        XmlSchemaSimpleTypeUnion union = XmlSchemaSimpleTypeUnion.Read(reader, h);
                        if (union != null)
                        {
                            stype.content = union;
                        }
                        continue;
                    }
                }
                reader.RaiseInvalidElementError();
            }
            return(stype);
        }
        internal static void FinishBuiltinType(XmlSchemaSimpleType derivedType, XmlSchemaSimpleType baseType)
        {
            derivedType.SetBaseSchemaType(baseType);
            derivedType.SetDerivedBy(XmlSchemaDerivationMethod.Restriction);
            if (derivedType.Datatype.Variety == XmlSchemaDatatypeVariety.Atomic)
            {
                XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction {
                    BaseTypeName = baseType.QualifiedName
                };
                derivedType.Content = restriction;
            }
            if (derivedType.Datatype.Variety == XmlSchemaDatatypeVariety.List)
            {
                XmlSchemaSimpleTypeList list = new XmlSchemaSimpleTypeList();
                derivedType.SetDerivedBy(XmlSchemaDerivationMethod.List);
                switch (derivedType.Datatype.TypeCode)
                {
                    case XmlTypeCode.Idref:
                        list.ItemType = list.BaseItemType = enumToTypeCode[0x26];
                        break;

                    case XmlTypeCode.Entity:
                        list.ItemType = list.BaseItemType = enumToTypeCode[0x27];
                        break;

                    case XmlTypeCode.NmToken:
                        list.ItemType = list.BaseItemType = enumToTypeCode[0x22];
                        break;
                }
                derivedType.Content = list;
            }
        }
 private XmlSchemaType ExportEnumMapping(EnumMapping mapping, string ns)
 {
     if (!mapping.IncludeInSchema)
     {
         throw new InvalidOperationException(Res.GetString("XmlCannotIncludeInSchema", new object[] { mapping.TypeDesc.Name }));
     }
     XmlSchemaSimpleType type = (XmlSchemaSimpleType) this.types[mapping];
     if (type == null)
     {
         this.CheckForDuplicateType(mapping, mapping.Namespace);
         type = new XmlSchemaSimpleType {
             Name = mapping.TypeName
         };
         if (!mapping.IsAnonymousType)
         {
             this.types.Add(mapping, type);
             this.AddSchemaItem(type, mapping.Namespace, ns);
         }
         XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction {
             BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")
         };
         for (int i = 0; i < mapping.Constants.Length; i++)
         {
             ConstantMapping mapping2 = mapping.Constants[i];
             XmlSchemaEnumerationFacet item = new XmlSchemaEnumerationFacet {
                 Value = mapping2.XmlName
             };
             restriction.Facets.Add(item);
         }
         if (!mapping.IsFlags)
         {
             type.Content = restriction;
         }
         else
         {
             XmlSchemaSimpleTypeList list = new XmlSchemaSimpleTypeList();
             XmlSchemaSimpleType type2 = new XmlSchemaSimpleType {
                 Content = restriction
             };
             list.ItemType = type2;
             type.Content = list;
         }
     }
     if (!mapping.IsAnonymousType)
     {
         this.AddSchemaImport(mapping.Namespace, ns);
     }
     return type;
 }
        EnumDataContract ImportFlagsEnum(XmlQualifiedName typeName, XmlSchemaSimpleTypeList list, XmlSchemaAnnotation annotation)
        {
            XmlSchemaSimpleType anonymousType = list.ItemType;
            if (anonymousType == null)
                ThrowEnumTypeCannotBeImportedException(typeName.Name, typeName.Namespace, SR.GetString(SR.EnumListMustContainAnonymousType));

            XmlSchemaSimpleTypeContent content = anonymousType.Content;
            if (content is XmlSchemaSimpleTypeUnion)
                ThrowEnumTypeCannotBeImportedException(typeName.Name, typeName.Namespace, SR.GetString(SR.EnumUnionInAnonymousTypeNotSupported));
            else if (content is XmlSchemaSimpleTypeList)
                ThrowEnumTypeCannotBeImportedException(typeName.Name, typeName.Namespace, SR.GetString(SR.EnumListInAnonymousTypeNotSupported));
            else if (content is XmlSchemaSimpleTypeRestriction)
            {
                XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction)content;
                if (CheckIfEnum(restriction))
                    return ImportEnum(typeName, restriction, true /*isFlags*/, annotation);
                else
                    ThrowEnumTypeCannotBeImportedException(typeName.Name, typeName.Namespace, SR.GetString(SR.EnumRestrictionInvalid));
            }
            return null;
        }
 internal override XmlSchemaObject Clone()
 {
     XmlSchemaSimpleTypeList newList = (XmlSchemaSimpleTypeList)MemberwiseClone();
     newList.ItemTypeName = _itemTypeName.Clone();
     return newList;
 }
 protected virtual void Visit(XmlSchemaSimpleTypeList list)
 {
     Traverse(list.BaseItemType);
 }
Beispiel #20
0
        //<list
        //  id = ID
        //  itemType = QName
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?, (simpleType?))
        //</list>
        internal static XmlSchemaSimpleTypeList Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaSimpleTypeList list = new XmlSchemaSimpleTypeList();

            reader.MoveToElement();

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

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

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

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(list);
            }
            //  Content: annotation?, simpleType?
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaSimpleTypeList.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)
                    {
                        list.Annotation = annotation;
                    }
                    continue;
                }
                if (level <= 2 && reader.LocalName == "simpleType")
                {
                    level = 3;
                    XmlSchemaSimpleType stype = XmlSchemaSimpleType.Read(reader, h);
                    if (stype != null)
                    {
                        list.itemType = stype;
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(list);
        }
        void ExportEnumDataContract(EnumDataContract enumDataContract, XmlSchema schema)
        {
            XmlSchemaSimpleType type = new XmlSchemaSimpleType();
            type.Name = enumDataContract.StableName.Name;
            XmlElement actualTypeElement = (enumDataContract.BaseContractName == DefaultEnumBaseTypeName) ? null : ExportActualType(enumDataContract.BaseContractName);
            type.Annotation = GetSchemaAnnotation(actualTypeElement, ExportSurrogateData(enumDataContract));
            schema.Items.Add(type);

            XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction();
            restriction.BaseTypeName = StringQualifiedName;
            SchemaHelper.AddSchemaImport(enumDataContract.BaseContractName.Namespace, schema);
            if (enumDataContract.Values != null)
            {
                for (int i = 0; i < enumDataContract.Values.Count; i++)
                {
                    XmlSchemaEnumerationFacet facet = new XmlSchemaEnumerationFacet();
                    facet.Value = enumDataContract.Members[i].Name;
                    if (enumDataContract.Values[i] != GetDefaultEnumValue(enumDataContract.IsFlags, i))
                        facet.Annotation = GetSchemaAnnotation(EnumerationValueAnnotationName, enumDataContract.GetStringFromEnumValue(enumDataContract.Values[i]), schema);
                    restriction.Facets.Add(facet);
                }
            }
            if (enumDataContract.IsFlags)
            {
                XmlSchemaSimpleTypeList list = new XmlSchemaSimpleTypeList();
                XmlSchemaSimpleType anonymousType = new XmlSchemaSimpleType();
                anonymousType.Content = restriction;
                list.ItemType = anonymousType;
                type.Content = list;
            }
            else
                type.Content = restriction;
        }
Beispiel #22
0
		void ExportEnumSchema (XmlTypeMapping map)
		{
			if (IsMapExported (map)) return;
			SetMapExported (map);

			XmlSchema schema = GetSchema (map.XmlTypeNamespace);
			XmlSchemaSimpleType stype = new XmlSchemaSimpleType ();
			stype.Name = map.ElementName;
			schema.Items.Add (stype);

			XmlSchemaSimpleTypeRestriction rest = new XmlSchemaSimpleTypeRestriction ();
			rest.BaseTypeName = new XmlQualifiedName ("string",XmlSchema.Namespace);
			EnumMap emap = (EnumMap) map.ObjectMap;

			foreach (EnumMap.EnumMapMember emem in emap.Members)
			{
				XmlSchemaEnumerationFacet ef = new XmlSchemaEnumerationFacet ();
				ef.Value = emem.XmlName;
				rest.Facets.Add (ef);
			}

			if (emap.IsFlags) {
				XmlSchemaSimpleTypeList slist = new XmlSchemaSimpleTypeList ();
				XmlSchemaSimpleType restrictionType = new XmlSchemaSimpleType ();
				restrictionType.Content = rest;
				slist.ItemType = restrictionType;
				stype.Content = slist;
			} else {
				stype.Content = rest;
			}
		}
 private void Write14_XmlSchemaSimpleTypeList(XmlSchemaSimpleTypeList o)
 {
     if (o != null)
     {
         this.WriteStartElement("list");
         this.WriteAttribute("id", "", o.Id);
         this.WriteAttributes(o.UnhandledAttributes, o);
         if (!o.ItemTypeName.IsEmpty)
         {
             this.WriteAttribute("itemType", "", o.ItemTypeName);
         }
         this.Write5_XmlSchemaAnnotation(o.Annotation);
         this.Write9_XmlSchemaSimpleType(o.ItemType);
         this.WriteEndElement();
     }
 }
        XmlSchemaType ExportEnumMapping(EnumMapping mapping, string ns) {
            if (!mapping.IncludeInSchema) throw new InvalidOperationException(Res.GetString(Res.XmlCannotIncludeInSchema, mapping.TypeDesc.Name));
            XmlSchemaSimpleType dataType = (XmlSchemaSimpleType)types[mapping];
            if (dataType == null) {
                CheckForDuplicateType(mapping, mapping.Namespace);
                dataType = new XmlSchemaSimpleType();
                dataType.Name = mapping.TypeName;
                if (!mapping.IsAnonymousType) {
                    types.Add(mapping, dataType);
                    AddSchemaItem(dataType, mapping.Namespace, ns);
                }
                XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction();
                restriction.BaseTypeName = new XmlQualifiedName("string", XmlSchema.Namespace);

                for (int i = 0; i < mapping.Constants.Length; i++) {
                    ConstantMapping constant = mapping.Constants[i];
                    XmlSchemaEnumerationFacet enumeration = new XmlSchemaEnumerationFacet();
                    enumeration.Value = constant.XmlName;
                    restriction.Facets.Add(enumeration);
                }
                if (!mapping.IsFlags) {
                    dataType.Content = restriction;
                }
                else {
                    XmlSchemaSimpleTypeList list = new XmlSchemaSimpleTypeList();
                    XmlSchemaSimpleType enumType = new XmlSchemaSimpleType();
                    enumType.Content =  restriction;
                    list.ItemType = enumType;
                    dataType.Content =  list;
                }
            }
            if (!mapping.IsAnonymousType) {
                AddSchemaImport(mapping.Namespace, ns);
            }
            return dataType;
        }
Beispiel #25
0
		public virtual void Check (ConformanceCheckContext ctx, XmlSchemaSimpleTypeList value) {}
        static void AddQNameListType(DiscoveryVersion discoveryVersion, XmlSchema schema)
        {
            // <xs:simpleType name="QNameListType">
            XmlSchemaSimpleType qNameListType = new XmlSchemaSimpleType();
            qNameListType.Name = ProtocolStrings.SchemaNames.QNameListType;

            // <xs:list itemType="xs:QName" />
            XmlSchemaSimpleTypeList qNameListTypeContent = new XmlSchemaSimpleTypeList();
            qNameListTypeContent.ItemTypeName = discoveryVersion.Implementation.QualifiedNames.QNameType;

            // </xs:simpleType>
            qNameListType.Content = qNameListTypeContent;

            schema.Items.Add(qNameListType);
        }
Beispiel #27
0
        XmlQualifiedName ExportEnumMapping(EnumMapping mapping, string ns) {
            XmlSchemaSimpleType dataType = (XmlSchemaSimpleType)types[mapping];
            if (dataType == null) {
                CheckForDuplicateType(mapping.TypeName, mapping.Namespace);
                dataType = new XmlSchemaSimpleType();
                dataType.Name = mapping.TypeName;
                types.Add(mapping, dataType);
                AddSchemaItem(dataType, mapping.Namespace, ns);

                XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction();
                restriction.BaseTypeName = new XmlQualifiedName("string", XmlSchema.Namespace);

                for (int i = 0; i < mapping.Constants.Length; i++) {
                    ConstantMapping constant = mapping.Constants[i];
                    XmlSchemaEnumerationFacet enumeration = new XmlSchemaEnumerationFacet();
                    enumeration.Value = constant.XmlName;
                    restriction.Facets.Add(enumeration);
                }
                if (!mapping.IsFlags) {
                    dataType.Content = restriction;
                }
                else {
                    XmlSchemaSimpleTypeList list = new XmlSchemaSimpleTypeList();
                    XmlSchemaSimpleType enumType = new XmlSchemaSimpleType();
                    enumType.Content =  restriction;
                    list.ItemType = enumType;
                    dataType.Content =  list;
                }
            }
            else {
                AddSchemaImport(mapping.Namespace, ns);
            }
            return new XmlQualifiedName(mapping.TypeName, mapping.Namespace);
        }
		XmlCompletionItemCollection GetAttributeValueCompletion(XmlSchemaSimpleTypeList list)
		{
			XmlCompletionItemCollection completionItems = new XmlCompletionItemCollection();
			
			if (list.ItemType != null) {
				completionItems.AddRange(GetAttributeValueCompletion(list.ItemType));
			} else if (list.ItemTypeName != null) {
				XmlSchemaSimpleType simpleType = FindSimpleType(list.ItemTypeName);
				if (simpleType != null) {
					completionItems.AddRange(GetAttributeValueCompletion(simpleType));
				}
			}
			
			return completionItems;
		}
Beispiel #29
0
        /// <summary>
        /// Create and add an element to a service descriptions schema. Used to create a native XmlType element.
        /// </summary>
        /// <param name="elementName">A string contininig the name of an element.</param>
        /// <param name="elementTypeNs">A string containing the namespace of the type.</param>
        /// <param name="xmlTypeName">A string containing the name of an element type.</param>
        /// <param name="isArray">True if the element represents an array of native types.</param>
        /// <param name="serviceDesc">The ServiceDescription used to store Wsdl definition.</param>
        private void AddNativeTypeElement(string elementName, string elementNs, string xmlTypeName, bool isArray, ServiceDescription serviceDesc)
        {
            XmlSchema schema = FindSchemaByNamespace(elementNs, serviceDesc.Types.Schemas);
            if (schema == null)
            {
                schema = new XmlSchema();
                serviceDesc.Types.Schemas.Add(schema);
                schema.TargetNamespace = FixupNamespace(elementNs);
            }

            // Add the element to the schema
            XmlSchemaElement element = new XmlSchemaElement();
            element.Name = elementName;
            if (isArray)
                element.SchemaTypeName = new XmlQualifiedName(elementName + "ListType", elementNs);
            else
                element.SchemaTypeName = new XmlQualifiedName(xmlTypeName, "http://www.w3.org/2001/XMLSchema");
            AddSchemaItem(schema, element);

            // If this is an array add a simple list type
            if (isArray)
            {
                XmlSchemaSimpleType simpleType = new XmlSchemaSimpleType();
                simpleType.Name = elementName + "ListType";
                XmlSchemaSimpleTypeList simpleContent = new XmlSchemaSimpleTypeList();
                simpleContent.ItemTypeName = new XmlQualifiedName(xmlTypeName, "http://www.w3.org/2001/XMLSchema");
                simpleType.Content = simpleContent;
                AddSchemaItem(schema, simpleType);
            }
            return;
        }
Beispiel #30
0
        internal override int Validate(ValidationEventHandler h, XmlSchema schema)
        {
            // 3.14.6 Properties Correct.
            //
            // 1. Post Compilation Properties
            // {name}, {target namespace} => QNameInternal. Already Compile()d.
            // {base type definition} => baseSchemaTypeInternal
            // {final} => finalResolved. Already Compile()d.
            // {variety} => resolvedDerivedBy. Already Compile()d.
            //
            // 2. Should be checked by "recursed" field.

            if (IsValidated(schema.ValidationId))
            {
                return(errorCount);
            }

            if (recursed)
            {
                error(h, "Circular type reference was found.");
                return(errorCount);
            }
            recursed = true;

            CollectBaseType(h, schema);

            if (content != null)
            {
                errorCount += content.Validate(h, schema);
            }

/*
 *                      // BaseSchemaType property
 *                      BaseXmlSchemaTypeInternal = content.ActualBaseSchemaType as XmlSchemaType;
 *                      if (this.BaseXmlSchemaTypeInternal == null)
 *                              this.DatatypeInternal = content.ActualBaseSchemaType as XmlSchemaDatatype;
 */

            // Datatype property
            XmlSchemaSimpleType simple = BaseXmlSchemaType as XmlSchemaSimpleType;

            if (simple != null)
            {
                this.DatatypeInternal = simple.Datatype;
            }
//			else
//				DatatypeInternal = BaseSchemaType as XmlSchemaDatatype;

            // 3.
            XmlSchemaSimpleType baseSType = BaseXmlSchemaType as XmlSchemaSimpleType;

            if (baseSType != null)
            {
                if ((baseSType.FinalResolved & this.resolvedDerivedBy) != 0)
                {
                    error(h, "Specified derivation is prohibited by the base simple type.");
                }
            }

            // {variety}
            if (this.resolvedDerivedBy == XmlSchemaDerivationMethod.Restriction &&
                baseSType != null)
            {
                this.variety = baseSType.Variety;
            }
            else
            {
                this.variety = this.resolvedDerivedBy;
            }

            // 3.14.6 Derivation Valid (Restriction, Simple)
            XmlSchemaSimpleTypeRestriction r = Content as XmlSchemaSimpleTypeRestriction;
            object baseType = BaseXmlSchemaType != null ? (object)BaseXmlSchemaType : Datatype;

            if (r != null)
            {
                ValidateDerivationValid(baseType, r.Facets, h, schema);
            }

            // TODO: describe which validation term this belongs to.
            XmlSchemaSimpleTypeList l = Content as XmlSchemaSimpleTypeList;

            if (l != null)
            {
                XmlSchemaSimpleType itemSimpleType = l.ValidatedListItemType as XmlSchemaSimpleType;
                if (itemSimpleType != null && itemSimpleType.Content is XmlSchemaSimpleTypeList)
                {
                    error(h, "List type must not be derived from another list type.");
                }
            }

            recursed     = false;
            ValidationId = schema.ValidationId;
            return(errorCount);
        }
Beispiel #31
0
        /// <summary>
        /// For a given type, generate a complex schema element. Recursively generate a complex type for any non
        /// native type referenced by this type. 
        /// </summary>
        /// <param name="members">An array of MemberInfo objects that contain the reflected details of the sub
        /// types continined within this type.</param>
        /// <param name="element">A reference to an XmlElement used to store the new element information.</param>
        /// <param name="schema">A Schema object used to store the new element.</param>
        /// <param name="schemaNamespace">A string containing the Schemas targetnamespace.</param>
        /// <param name="serviceDesc"></param>
        void ProcessDataMemberType(MemberInfo[] members, ref XmlSchemaElement element, XmlSchema schema, string schemaNamespace, ServiceDescription serviceDesc)
        {
            element.SchemaTypeName = new XmlQualifiedName(element.Name + "Type", schemaNamespace);
            if (AddSchemaItem(schema, element))
                return;

            XmlSchemaComplexType complexType = new XmlSchemaComplexType();
            complexType.Name = element.Name + "Type";
            complexType.Particle = new XmlSchemaSequence();
            if (AddSchemaItem(schema, complexType))
                return;

            // If members is null this type is an empty wrapper
            if (members == null)
                return;

            foreach (MemberInfo member in members)
            {
                FieldInfo fieldInfo = (FieldInfo)member;

                DataMemberAttrib dataMemberAttrib = GetDataMemberAttribute(fieldInfo);

                if (fieldInfo.FieldType.FullName != null)
                {
                    // Special handling if the field type is an array
                    bool isArray = false;
                    string fieldTypeName = fieldInfo.FieldType.FullName;
                    if (fieldTypeName.EndsWith("[]"))
                    {
                        isArray = true;
                        fieldTypeName = fieldTypeName.Substring(0, fieldTypeName.Length - 2);
                    }
                    
                    // If this is not a native type recurse and create the base type
                    string xmlTypeName = CodeGenUtils.GetXmlType(fieldTypeName);
                    if (xmlTypeName == null)
                    {
                        XmlSchemaElement elementItem = new XmlSchemaElement();
                        elementItem.RefName = new XmlQualifiedName(fieldInfo.Name, schemaNamespace);
                        elementItem.MinOccurs = 0;
                        elementItem.MaxOccurs = 1;

                        // If the data member has modifiers reset values
                        bool isAttribute = false;
                        if (dataMemberAttrib != null)
                        {
                            elementItem.MinOccurs = dataMemberAttrib.IsRequired ? 1 : 0;
                            if (dataMemberAttrib.Name != null)
                                elementItem.RefName = new XmlQualifiedName(dataMemberAttrib.Name, schemaNamespace);
                            isAttribute = dataMemberAttrib.IsAttribute;
                        }
                        
                        if (isArray)
                        {
                            string fieldName = fieldInfo.FieldType.Name;
                            fieldName = fieldName.Substring(0, fieldName.Length - 2);
                            ProcessDataContract(fieldInfo.FieldType.GetElementType(), schemaNamespace, serviceDesc);
                            elementItem.MaxOccursString = "unbounded";
                        }
                        else
                        {
                            ProcessDataContract(fieldInfo.FieldType, schemaNamespace, serviceDesc);
                        }

                        // If order is set insert element at order position
                        if (dataMemberAttrib != null && dataMemberAttrib.Order >= 0)
                            ((XmlSchemaSequence)complexType.Particle).Items.Insert(dataMemberAttrib.Order, elementItem);
                        else
                            ((XmlSchemaSequence)complexType.Particle).Items.Add(elementItem);
                    }
                    else{

                        Logger.WriteLine("        Field = " + fieldInfo.FieldType.UnderlyingSystemType + " " + fieldInfo.Name, LogLevel.Verbose);
                        XmlSchemaElement elementItem = new XmlSchemaElement();
                        elementItem.Name = fieldInfo.Name;

                        // Process any types
                        if (xmlTypeName == "any")
                        {
                            XmlSchemaAny anyElement = new XmlSchemaAny();
                            anyElement.MinOccurs = 0;
                            anyElement.MaxOccursString = "unbounded";
                            anyElement.Namespace = "##other";
                            anyElement.ProcessContents = XmlSchemaContentProcessing.Lax;
                            ((XmlSchemaSequence)complexType.Particle).Items.Add(anyElement);
                        }
                        else if (xmlTypeName == "anyAttribute")
                        {
                            XmlSchemaAnyAttribute anyAttribute = new XmlSchemaAnyAttribute();
                            anyAttribute.Namespace = "##any";
                            anyAttribute.ProcessContents = XmlSchemaContentProcessing.Lax;
                            complexType.AnyAttribute = anyAttribute;
                        }
                        else
                        {
                            elementItem.MinOccurs = 1;
                            elementItem.MaxOccurs = 1;
                            if (dataMemberAttrib != null)
                            {
                                if (dataMemberAttrib.IsAttribute)
                                {
                                    XmlSchemaAttribute attrib = new XmlSchemaAttribute();
                                    attrib.SchemaTypeName = new XmlQualifiedName(xmlTypeName, "http://www.w3.org/2001/XMLSchema");
                                    attrib.Name = fieldInfo.FieldType.Name;
                                    if (dataMemberAttrib.IsRequired)
                                        attrib.Use = XmlSchemaUse.Required;
                                    return;
                                }
                                elementItem.MinOccurs = dataMemberAttrib.IsRequired ? 1 : 0;
                                elementItem.IsNillable = dataMemberAttrib.IsNillable;
                            }
                            
                            // If the type is an array create a simple List type before adding the element particle
                            if (isArray && xmlTypeName != "base64Binary")
                            {
                                XmlSchemaSimpleType simpleType = new XmlSchemaSimpleType();
                                simpleType.Name = fieldInfo.Name + "ListType";
                                XmlSchemaSimpleTypeList simpleContent = new XmlSchemaSimpleTypeList();
                                string itemTypeName = fieldInfo.FieldType.FullName;
                                itemTypeName = itemTypeName.Substring(0, itemTypeName.Length - 2);
                                simpleContent.ItemTypeName = new XmlQualifiedName(CodeGenUtils.GetXmlType(itemTypeName), "http://www.w3.org/2001/XMLSchema");
                                simpleType.Content = simpleContent;
                                AddSchemaItem(schema, simpleType);
                                elementItem.SchemaTypeName = new XmlQualifiedName(simpleType.Name, schemaNamespace);
                            }
                            else
                                elementItem.SchemaTypeName = new XmlQualifiedName(xmlTypeName, "http://www.w3.org/2001/XMLSchema");
                            ((XmlSchemaSequence)complexType.Particle).Items.Add(elementItem);
                        }
                    }
                }
            }
        }
 private void ExportAttributeAccessor(XmlSchemaComplexType type, AttributeAccessor accessor, bool valueTypeOptional, string ns)
 {
     if (accessor != null)
     {
         XmlSchemaObjectCollection attributes;
         if (type.ContentModel != null)
         {
             if (type.ContentModel.Content is XmlSchemaComplexContentRestriction)
             {
                 attributes = ((XmlSchemaComplexContentRestriction) type.ContentModel.Content).Attributes;
             }
             else if (!(type.ContentModel.Content is XmlSchemaComplexContentExtension))
             {
                 if (!(type.ContentModel.Content is XmlSchemaSimpleContentExtension))
                 {
                     throw new InvalidOperationException(Res.GetString("XmlInvalidContent", new object[] { type.ContentModel.Content.GetType().Name }));
                 }
                 attributes = ((XmlSchemaSimpleContentExtension) type.ContentModel.Content).Attributes;
             }
             else
             {
                 attributes = ((XmlSchemaComplexContentExtension) type.ContentModel.Content).Attributes;
             }
         }
         else
         {
             attributes = type.Attributes;
         }
         if (accessor.IsSpecialXmlNamespace)
         {
             this.AddSchemaImport("http://www.w3.org/XML/1998/namespace", ns);
             XmlSchemaAttribute item = new XmlSchemaAttribute {
                 Use = XmlSchemaUse.Optional,
                 RefName = new XmlQualifiedName(accessor.Name, "http://www.w3.org/XML/1998/namespace")
             };
             attributes.Add(item);
         }
         else if (accessor.Any)
         {
             if (type.ContentModel == null)
             {
                 type.AnyAttribute = new XmlSchemaAnyAttribute();
             }
             else
             {
                 XmlSchemaContent content = type.ContentModel.Content;
                 if (content is XmlSchemaComplexContentExtension)
                 {
                     XmlSchemaComplexContentExtension extension = (XmlSchemaComplexContentExtension) content;
                     extension.AnyAttribute = new XmlSchemaAnyAttribute();
                 }
                 else if (content is XmlSchemaComplexContentRestriction)
                 {
                     XmlSchemaComplexContentRestriction restriction = (XmlSchemaComplexContentRestriction) content;
                     restriction.AnyAttribute = new XmlSchemaAnyAttribute();
                 }
                 else if (type.ContentModel.Content is XmlSchemaSimpleContentExtension)
                 {
                     XmlSchemaSimpleContentExtension extension2 = (XmlSchemaSimpleContentExtension) content;
                     extension2.AnyAttribute = new XmlSchemaAnyAttribute();
                 }
             }
         }
         else
         {
             XmlSchemaAttribute attribute2 = new XmlSchemaAttribute {
                 Use = XmlSchemaUse.None
             };
             if ((!accessor.HasDefault && !valueTypeOptional) && accessor.Mapping.TypeDesc.IsValueType)
             {
                 attribute2.Use = XmlSchemaUse.Required;
             }
             attribute2.Name = accessor.Name;
             if ((accessor.Namespace == null) || (accessor.Namespace == ns))
             {
                 XmlSchema schema = this.schemas[ns];
                 if (schema == null)
                 {
                     attribute2.Form = (accessor.Form == XmlSchemaForm.Unqualified) ? XmlSchemaForm.None : accessor.Form;
                 }
                 else
                 {
                     attribute2.Form = (accessor.Form == schema.AttributeFormDefault) ? XmlSchemaForm.None : accessor.Form;
                 }
                 attributes.Add(attribute2);
             }
             else
             {
                 if (this.attributes[accessor] == null)
                 {
                     attribute2.Use = XmlSchemaUse.None;
                     attribute2.Form = accessor.Form;
                     this.AddSchemaItem(attribute2, accessor.Namespace, ns);
                     this.attributes.Add(accessor, accessor);
                 }
                 XmlSchemaAttribute attribute3 = new XmlSchemaAttribute {
                     Use = XmlSchemaUse.None,
                     RefName = new XmlQualifiedName(accessor.Name, accessor.Namespace)
                 };
                 attributes.Add(attribute3);
                 this.AddSchemaImport(accessor.Namespace, ns);
             }
             if (accessor.Mapping is PrimitiveMapping)
             {
                 PrimitiveMapping mapping = (PrimitiveMapping) accessor.Mapping;
                 if (mapping.IsList)
                 {
                     XmlSchemaSimpleType type2 = new XmlSchemaSimpleType();
                     XmlSchemaSimpleTypeList list = new XmlSchemaSimpleTypeList();
                     if (mapping.IsAnonymousType)
                     {
                         list.ItemType = (XmlSchemaSimpleType) this.ExportAnonymousPrimitiveMapping(mapping);
                     }
                     else
                     {
                         list.ItemTypeName = this.ExportPrimitiveMapping(mapping, (accessor.Namespace == null) ? ns : accessor.Namespace);
                     }
                     type2.Content = list;
                     attribute2.SchemaType = type2;
                 }
                 else if (mapping.IsAnonymousType)
                 {
                     attribute2.SchemaType = (XmlSchemaSimpleType) this.ExportAnonymousPrimitiveMapping(mapping);
                 }
                 else
                 {
                     attribute2.SchemaTypeName = this.ExportPrimitiveMapping(mapping, (accessor.Namespace == null) ? ns : accessor.Namespace);
                 }
             }
             else if (!(accessor.Mapping is SpecialMapping))
             {
                 throw new InvalidOperationException(Res.GetString("XmlInternalError"));
             }
             if (accessor.HasDefault)
             {
                 attribute2.DefaultValue = ExportDefaultValue(accessor.Mapping, accessor.Default);
             }
         }
     }
 }
		public override void Check (ConformanceCheckContext ctx, XmlSchemaSimpleTypeList value)
		{
			CheckSchemaQName (ctx, value, value.ItemTypeName);
		}
Beispiel #34
0
 private void SetContainer(State state, object container) {
     switch (state) {
         case State.Root:
             break;
         case State.Schema:
             break;
         case State.Annotation:
             this.annotation = (XmlSchemaAnnotation)container;
             break;
         case State.Include:
             this.include = (XmlSchemaInclude)container;
             break;
         case State.Import:
             this.import = (XmlSchemaImport)container;
             break;
         case State.Element:
             this.element = (XmlSchemaElement)container;
             break;
         case State.Attribute:
             this.attribute = (XmlSchemaAttribute)container;
             break;
         case State.AttributeGroup:
             this.attributeGroup = (XmlSchemaAttributeGroup)container;
             break;
         case State.AttributeGroupRef:
             this.attributeGroupRef = (XmlSchemaAttributeGroupRef)container;
             break;
         case State.AnyAttribute:
             this.anyAttribute = (XmlSchemaAnyAttribute)container;
             break;
         case State.Group:
             this.group = (XmlSchemaGroup)container;
             break;
         case State.GroupRef:
             this.groupRef = (XmlSchemaGroupRef)container;
             break;
         case State.All:
             this.all = (XmlSchemaAll)container;
             break;
         case State.Choice:
             this.choice = (XmlSchemaChoice)container;
             break;
         case State.Sequence:
             this.sequence = (XmlSchemaSequence)container;
             break;
         case State.Any:
             this.anyElement = (XmlSchemaAny)container;
             break;
         case State.Notation:
             this.notation = (XmlSchemaNotation)container;
             break;
         case State.SimpleType:
             this.simpleType = (XmlSchemaSimpleType)container;
             break;
         case State.ComplexType:
             this.complexType = (XmlSchemaComplexType)container;
             break;
         case State.ComplexContent:
             this.complexContent = (XmlSchemaComplexContent)container;
             break;
         case State.ComplexContentExtension:
             this.complexContentExtension = (XmlSchemaComplexContentExtension)container;
             break;
         case State.ComplexContentRestriction:
             this.complexContentRestriction = (XmlSchemaComplexContentRestriction)container;
             break;
         case State.SimpleContent:
             this.simpleContent = (XmlSchemaSimpleContent)container;
             break;
         case State.SimpleContentExtension:
             this.simpleContentExtension = (XmlSchemaSimpleContentExtension)container;
             break;
         case State.SimpleContentRestriction:
             this.simpleContentRestriction = (XmlSchemaSimpleContentRestriction)container;
             break;
         case State.SimpleTypeUnion:
             this.simpleTypeUnion = (XmlSchemaSimpleTypeUnion)container;
             break;
         case State.SimpleTypeList:
             this.simpleTypeList = (XmlSchemaSimpleTypeList)container;
             break;
         case State.SimpleTypeRestriction:
             this.simpleTypeRestriction = (XmlSchemaSimpleTypeRestriction)container;
             break;
         case State.Unique:
         case State.Key:
         case State.KeyRef:
             this.identityConstraint = (XmlSchemaIdentityConstraint)container;
             break;
         case State.Selector:
         case State.Field:
             this.xpath = (XmlSchemaXPath)container;
             break;
         case State.MinExclusive:
         case State.MinInclusive:
         case State.MaxExclusive:
         case State.MaxInclusive:
         case State.TotalDigits:
         case State.FractionDigits:
         case State.Length:
         case State.MinLength:
         case State.MaxLength:
         case State.Enumeration:
         case State.Pattern:
         case State.WhiteSpace:
             this.facet = (XmlSchemaFacet)container;
             break;
         case State.AppInfo:
             this.appInfo = (XmlSchemaAppInfo)container;
             break;
         case State.Documentation:
             this.documentation = (XmlSchemaDocumentation)container;
             break;
         case State.Redefine:
             this.redefine = (XmlSchemaRedefine)container;
             break;
         default:
             Debug.Assert(false, "State is " + state);
             break;
     }
 }
		XmlCompletionDataCollection GetAttributeValueCompletionData(XmlSchemaSimpleTypeList list)
		{
			XmlCompletionDataCollection data = new XmlCompletionDataCollection();
			
			if (list.ItemType != null) {
				data.AddRange(GetAttributeValueCompletionData(list.ItemType));
			} else if (list.ItemTypeName != null) {
				XmlSchemaSimpleType simpleType = FindSimpleType(list.ItemTypeName);
				if (simpleType != null) {
					data.AddRange(GetAttributeValueCompletionData(simpleType));
				}
			}
			
			return data;
		}	
 void Write14_XmlSchemaSimpleTypeList(XmlSchemaSimpleTypeList o) {
     if ((object)o == null) return;
     WriteStartElement("list");
     
     WriteAttribute(@"id", @"", ((System.String)o.@Id));
     WriteAttributes((XmlAttribute[])o.@UnhandledAttributes, o);
     if ([email protected]){
         WriteAttribute(@"itemType", @"", o.@ItemTypeName);
     }
     Write5_XmlSchemaAnnotation((XmlSchemaAnnotation)o.@Annotation);
     Write9_XmlSchemaSimpleType((XmlSchemaSimpleType)o.@ItemType);
     WriteEndElement();
 }
        internal static XmlSchemaSimpleType Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaSimpleType xmlSchemaSimpleType = new XmlSchemaSimpleType();

            reader.MoveToElement();
            if (reader.NamespaceURI != "http://www.w3.org/2001/XMLSchema" || reader.LocalName != "simpleType")
            {
                XmlSchemaObject.error(h, "Should not happen :1: XmlSchemaGroup.Read, name=" + reader.Name, null);
                reader.Skip();
                return(null);
            }
            xmlSchemaSimpleType.LineNumber   = reader.LineNumber;
            xmlSchemaSimpleType.LinePosition = reader.LinePosition;
            xmlSchemaSimpleType.SourceUri    = reader.BaseURI;
            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "final")
                {
                    Exception ex;
                    xmlSchemaSimpleType.Final = XmlSchemaUtil.ReadDerivationAttribute(reader, out ex, "final", XmlSchemaUtil.FinalAllowed);
                    if (ex != null)
                    {
                        XmlSchemaObject.error(h, "some invalid values not a valid value for final", ex);
                    }
                }
                else if (reader.Name == "id")
                {
                    xmlSchemaSimpleType.Id = reader.Value;
                }
                else if (reader.Name == "name")
                {
                    xmlSchemaSimpleType.Name = 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 simpleType", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, xmlSchemaSimpleType);
                }
            }
            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(xmlSchemaSimpleType);
            }
            int num = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != "simpleType")
                    {
                        XmlSchemaObject.error(h, "Should not happen :2: XmlSchemaSimpleType.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (num <= 1 && reader.LocalName == "annotation")
                {
                    num = 2;
                    XmlSchemaAnnotation xmlSchemaAnnotation = XmlSchemaAnnotation.Read(reader, h);
                    if (xmlSchemaAnnotation != null)
                    {
                        xmlSchemaSimpleType.Annotation = xmlSchemaAnnotation;
                    }
                }
                else
                {
                    if (num <= 2)
                    {
                        if (reader.LocalName == "restriction")
                        {
                            num = 3;
                            XmlSchemaSimpleTypeRestriction xmlSchemaSimpleTypeRestriction = XmlSchemaSimpleTypeRestriction.Read(reader, h);
                            if (xmlSchemaSimpleTypeRestriction != null)
                            {
                                xmlSchemaSimpleType.content = xmlSchemaSimpleTypeRestriction;
                            }
                            continue;
                        }
                        if (reader.LocalName == "list")
                        {
                            num = 3;
                            XmlSchemaSimpleTypeList xmlSchemaSimpleTypeList = XmlSchemaSimpleTypeList.Read(reader, h);
                            if (xmlSchemaSimpleTypeList != null)
                            {
                                xmlSchemaSimpleType.content = xmlSchemaSimpleTypeList;
                            }
                            continue;
                        }
                        if (reader.LocalName == "union")
                        {
                            num = 3;
                            XmlSchemaSimpleTypeUnion xmlSchemaSimpleTypeUnion = XmlSchemaSimpleTypeUnion.Read(reader, h);
                            if (xmlSchemaSimpleTypeUnion != null)
                            {
                                xmlSchemaSimpleType.content = xmlSchemaSimpleTypeUnion;
                            }
                            continue;
                        }
                    }
                    reader.RaiseInvalidElementError();
                }
            }
            return(xmlSchemaSimpleType);
        }