示例#1
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);
        }
示例#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;

#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
        }
示例#3
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);
        }
示例#4
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);
        }