상속: SchemaBuilder
예제 #1
0
        public async Task StartParsingAsync(XmlReader reader, string targetNamespace) {
            this.reader = reader;
            positionInfo = PositionInfo.GetPositionInfo(reader);
            namespaceManager = reader.NamespaceManager;
            if (namespaceManager == null) {
                namespaceManager = new XmlNamespaceManager(nameTable);
                isProcessNamespaces = true;
            } 
            else {
                isProcessNamespaces = false;
            }
            while (reader.NodeType != XmlNodeType.Element && await reader.ReadAsync().ConfigureAwait(false)) {}

            markupDepth = int.MaxValue;
            schemaXmlDepth = reader.Depth;
            SchemaType rootType = schemaNames.SchemaTypeFromRoot(reader.LocalName, reader.NamespaceURI);
            
            string code;
            if (!CheckSchemaRoot(rootType, out code)) {
                throw new XmlSchemaException(code, reader.BaseURI, positionInfo.LineNumber, positionInfo.LinePosition);
            }
            
            if (schemaType == SchemaType.XSD) {
                schema = new XmlSchema();
                schema.BaseUri = new Uri(reader.BaseURI, UriKind.RelativeOrAbsolute);
                builder = new XsdBuilder(reader, namespaceManager, schema, nameTable, schemaNames, eventHandler);
            }
            else {  
                Debug.Assert(schemaType == SchemaType.XDR);
                xdrSchema = new SchemaInfo();
                xdrSchema.SchemaType = SchemaType.XDR;
                builder = new XdrBuilder(reader, namespaceManager, xdrSchema, targetNamespace, nameTable, schemaNames, eventHandler);
                ((XdrBuilder)builder).XmlResolver = xmlResolver;
            }
        }
예제 #2
0
파일: XdrBuilder.cs 프로젝트: dotnet/corefx
 private static void XDR_EndAttribute(XdrBuilder builder)
 {
     builder._BaseDecl.Reset();
 }
예제 #3
0
파일: XdrBuilder.cs 프로젝트: dotnet/corefx
        private static void XDR_BeginElementType(XdrBuilder builder)
        {
            string code = null;
            string msg = null;

            //
            // check name attribute
            //
            if (builder._ElementDef._ElementDecl.Name.IsEmpty)
            {
                code = SR.Sch_MissAttribute;
                msg = "name";
                goto cleanup;
            }

            //
            // check dt:type attribute
            //
            if (builder._ElementDef._HasDataType)
            {
                if (!builder._ElementDef._AllowDataType)
                {
                    code = SR.Sch_DataTypeTextOnly;
                    goto cleanup;
                }
                else
                {
                    builder._ElementDef._ContentAttr = SchemaContentText;
                }
            }
            else if (builder._ElementDef._ContentAttr == SchemaContentNone)
            {
                switch (builder._ElementDef._OrderAttr)
                {
                    case SchemaOrderNone:
                        builder._ElementDef._ContentAttr = SchemaContentMixed;
                        builder._ElementDef._OrderAttr = SchemaOrderMany;
                        break;
                    case SchemaOrderSequence:
                        builder._ElementDef._ContentAttr = SchemaContentElement;
                        break;
                    case SchemaOrderChoice:
                        builder._ElementDef._ContentAttr = SchemaContentElement;
                        break;
                    case SchemaOrderMany:
                        builder._ElementDef._ContentAttr = SchemaContentMixed;
                        break;
                }
            }


            //save the model value from the base
            bool tempOpen = builder._contentValidator.IsOpen;
            ElementContent def = builder._ElementDef;
            switch (builder._ElementDef._ContentAttr)
            {
                case SchemaContentText:
                    builder._ElementDef._ElementDecl.ContentValidator = ContentValidator.TextOnly;
                    builder._GroupDef._Order = SchemaOrderMany;
                    builder._contentValidator = null;
                    break;
                case SchemaContentElement:
                    builder._contentValidator = new ParticleContentValidator(XmlSchemaContentType.ElementOnly);
                    if (def._OrderAttr == SchemaOrderNone)
                    {
                        builder._GroupDef._Order = SchemaOrderSequence;
                    }
                    def._MasterGroupRequired = true;
                    builder._contentValidator.IsOpen = tempOpen;
                    break;

                case SchemaContentEmpty:
                    builder._ElementDef._ElementDecl.ContentValidator = ContentValidator.Empty;
                    builder._contentValidator = null;
                    break;

                case SchemaContentMixed:
                    if (def._OrderAttr == SchemaOrderNone || def._OrderAttr == SchemaOrderMany)
                    {
                        builder._GroupDef._Order = SchemaOrderMany;
                    }
                    else
                    {
                        code = SR.Sch_MixedMany;
                        goto cleanup;
                    }
                    def._MasterGroupRequired = true;
                    builder._contentValidator.IsOpen = tempOpen;
                    break;
            }


            if (def._ContentAttr == SchemaContentMixed || def._ContentAttr == SchemaContentElement)
            {
                builder._contentValidator.Start();
                builder._contentValidator.OpenGroup();
            }
        cleanup:
            if (code != null)
            {
                builder.SendValidationEvent(code, msg);
            }
        }
예제 #4
0
파일: XdrBuilder.cs 프로젝트: dotnet/corefx
 private static void XDR_BuildElementType_DtValues(XdrBuilder builder, object obj, string prefix)
 {
     builder._ElementDef._EnumerationRequired = true;
     builder._ElementDef._ElementDecl.Values = new List<string>((string[])obj);
 }
예제 #5
0
파일: XdrBuilder.cs 프로젝트: dotnet/corefx
 private static void XDR_BuildElementType_Order(XdrBuilder builder, object obj, string prefix)
 {
     builder._ElementDef._OrderAttr = builder._GroupDef._Order = builder.GetOrder((XmlQualifiedName)obj);
 }
예제 #6
0
파일: XdrBuilder.cs 프로젝트: dotnet/corefx
 private static void XDR_BuildElementType_Content(XdrBuilder builder, object obj, string prefix)
 {
     builder._ElementDef._ContentAttr = builder.GetContent((XmlQualifiedName)obj);
 }
예제 #7
0
파일: XdrBuilder.cs 프로젝트: dotnet/corefx
        //
        // XDR ElementType
        //

        private static void XDR_InitElementType(XdrBuilder builder, object obj)
        {
            builder._ElementDef._ElementDecl = new SchemaElementDecl();
            builder._contentValidator = new ParticleContentValidator(XmlSchemaContentType.Mixed);
            builder._contentValidator.IsOpen = true;

            builder._ElementDef._ContentAttr = SchemaContentNone;
            builder._ElementDef._OrderAttr = SchemaOrderNone;
            builder._ElementDef._MasterGroupRequired = false;
            builder._ElementDef._ExistTerminal = false;
            builder._ElementDef._AllowDataType = true;
            builder._ElementDef._HasDataType = false;
            builder._ElementDef._EnumerationRequired = false;
            builder._ElementDef._AttDefList = new Hashtable();
            builder._ElementDef._MaxLength = uint.MaxValue;
            builder._ElementDef._MinLength = uint.MaxValue;

            //        builder._AttributeDef._HasDataType = false;
            //        builder._AttributeDef._Default = null;
        }
예제 #8
0
파일: XdrBuilder.cs 프로젝트: dotnet/corefx
 private static void XDR_BeginRoot(XdrBuilder builder)
 {
     if (builder._TargetNamespace == null)
     { // inline xdr schema
         if (builder._XdrName != null)
         {
             builder._TargetNamespace = builder._NameTable.Add("x-schema:#" + builder._XdrName);
         }
         else
         {
             builder._TargetNamespace = String.Empty;
         }
     }
     builder._SchemaInfo.TargetNamespaces.Add(builder._TargetNamespace, true);
 }
예제 #9
0
파일: XdrBuilder.cs 프로젝트: dotnet/corefx
 private static void XDR_InitAttributeDtType(XdrBuilder builder, object obj)
 {
     if (builder._AttributeDef._HasDataType)
     {
         builder.SendValidationEvent(SR.Sch_DupDtType);
     }
 }
예제 #10
0
파일: XdrBuilder.cs 프로젝트: dotnet/corefx
 private static void XDR_EndElementDtType(XdrBuilder builder)
 {
     if (!builder._ElementDef._HasDataType)
     {
         builder.SendValidationEvent(SR.Sch_MissAttribute);
     }
     builder._ElementDef._ElementDecl.ContentValidator = ContentValidator.TextOnly;
     builder._ElementDef._ContentAttr = SchemaContentText;
     builder._ElementDef._MasterGroupRequired = false;
     builder._contentValidator = null;
 }
예제 #11
0
파일: XdrBuilder.cs 프로젝트: dotnet/corefx
        //
        // DataType
        //

        private static void XDR_InitElementDtType(XdrBuilder builder, object obj)
        {
            if (builder._ElementDef._HasDataType)
            {
                builder.SendValidationEvent(SR.Sch_DupDtType);
            }

            if (!builder._ElementDef._AllowDataType)
            {
                builder.SendValidationEvent(SR.Sch_DataTypeTextOnly);
            }
        }
예제 #12
0
파일: XdrBuilder.cs 프로젝트: dotnet/corefx
        //    private static void XDR_BeginGroup(XdrBuilder builder)
        //    {
        //
        //    }


        private static void XDR_EndGroup(XdrBuilder builder)
        {
            if (!builder._ElementDef._ExistTerminal)
            {
                builder.SendValidationEvent(SR.Sch_ElementMissing);
            }

            builder._contentValidator.CloseGroup();

            if (builder._GroupDef._Order == SchemaOrderMany)
            {
                builder._contentValidator.AddStar();
            }

            if (SchemaOrderMany == builder._GroupDef._Order &&
                builder._GroupDef._HasMaxAttr &&
                builder._GroupDef._MaxVal != uint.MaxValue)
            {
                builder.SendValidationEvent(SR.Sch_ManyMaxOccurs);
            }

            HandleMinMax(builder._contentValidator,
                         builder._GroupDef._MinVal,
                         builder._GroupDef._MaxVal);

            builder.PopGroupInfo();
        }
예제 #13
0
파일: XdrBuilder.cs 프로젝트: dotnet/corefx
 private static void XDR_BuildGroup_MaxOccurs(XdrBuilder builder, object obj, string prefix)
 {
     builder._GroupDef._MaxVal = ParseMaxOccurs(obj, builder);
     builder._GroupDef._HasMaxAttr = true;
 }
예제 #14
0
파일: XdrBuilder.cs 프로젝트: dotnet/corefx
 private static void XDR_BuildGroup_Order(XdrBuilder builder, object obj, string prefix)
 {
     builder._GroupDef._Order = builder.GetOrder((XmlQualifiedName)obj);
     if (builder._ElementDef._ContentAttr == SchemaContentMixed && builder._GroupDef._Order != SchemaOrderMany)
     {
         builder.SendValidationEvent(SR.Sch_MixedMany);
     }
 }
예제 #15
0
파일: XdrBuilder.cs 프로젝트: dotnet/corefx
        //
        // XDR Group
        //

        private static void XDR_InitGroup(XdrBuilder builder, object obj)
        {
            if (builder._ElementDef._ContentAttr == SchemaContentEmpty ||
                builder._ElementDef._ContentAttr == SchemaContentText)
            {
                builder.SendValidationEvent(SR.Sch_GroupDisabled);
            }

            builder.PushGroupInfo();

            builder._GroupDef._MinVal = 1;
            builder._GroupDef._MaxVal = 1;
            builder._GroupDef._HasMaxAttr = false;
            builder._GroupDef._HasMinAttr = false;

            if (builder._ElementDef._ExistTerminal)
                builder.AddOrder();

            // now we are in a group so we reset fExistTerminal
            builder._ElementDef._ExistTerminal = false;

            builder._contentValidator.OpenGroup();
        }
예제 #16
0
파일: XdrBuilder.cs 프로젝트: dotnet/corefx
 private static void XDR_BuildRoot_Name(XdrBuilder builder, object obj, string prefix)
 {
     builder._XdrName = (string)obj;
     builder._XdrPrefix = prefix;
 }
예제 #17
0
파일: XdrBuilder.cs 프로젝트: dotnet/corefx
 private static void XDR_BuildRoot_ID(XdrBuilder builder, object obj, string prefix)
 {
 }
예제 #18
0
파일: XdrBuilder.cs 프로젝트: dotnet/corefx
        private static void XDR_EndAttributeDtType(XdrBuilder builder)
        {
            string code = null;

            if (!builder._AttributeDef._HasDataType)
            {
                code = SR.Sch_MissAttribute;
            }
            else
            {
                if (builder._AttributeDef._AttDef.Datatype != null)
                {
                    XmlTokenizedType ttype = builder._AttributeDef._AttDef.Datatype.TokenizedType;

                    if (ttype == XmlTokenizedType.ENUMERATION && !builder._AttributeDef._EnumerationRequired)
                    {
                        code = SR.Sch_MissDtvaluesAttribute;
                    }
                    else if (ttype != XmlTokenizedType.ENUMERATION && builder._AttributeDef._EnumerationRequired)
                    {
                        code = SR.Sch_RequireEnumeration;
                    }
                }
            }
            if (code != null)
            {
                builder.SendValidationEvent(code);
            }
        }
예제 #19
0
파일: XdrBuilder.cs 프로젝트: dotnet/corefx
        private static void XDR_EndRoot(XdrBuilder builder)
        {
            //
            // check undefined attribute types
            // We already checked local attribute types, so only need to check global attribute types here 
            //
            while (builder._UndefinedAttributeTypes != null)
            {
                XmlQualifiedName gname = builder._UndefinedAttributeTypes._TypeName;

                // if there is no URN in this name then the name is local to the
                // schema, but the global attribute was still URN qualified, so
                // we need to qualify this name now.
                if (gname.Namespace.Length == 0)
                {
                    gname = new XmlQualifiedName(gname.Name, builder._TargetNamespace);
                }
                SchemaAttDef ad;
                if (builder._SchemaInfo.AttributeDecls.TryGetValue(gname, out ad))
                {
                    builder._UndefinedAttributeTypes._Attdef = (SchemaAttDef)ad.Clone();
                    builder._UndefinedAttributeTypes._Attdef.Name = gname;
                    builder.XDR_CheckAttributeDefault(builder._UndefinedAttributeTypes, builder._UndefinedAttributeTypes._Attdef);
                }
                else
                {
                    builder.SendValidationEvent(SR.Sch_UndeclaredAttribute, gname.Name);
                }
                builder._UndefinedAttributeTypes = builder._UndefinedAttributeTypes._Next;
            }

            foreach (SchemaElementDecl ed in builder._UndeclaredElements.Values)
            {
                builder.SendValidationEvent(SR.Sch_UndeclaredElement, XmlQualifiedName.ToString(ed.Name.Name, ed.Prefix));
            }
        }
예제 #20
0
파일: XdrBuilder.cs 프로젝트: dotnet/corefx
        private static bool IsYes(object obj, XdrBuilder builder)
        {
            XmlQualifiedName qname = (XmlQualifiedName)obj;
            bool fYes = false;

            if (qname.Name == "yes")
            {
                fYes = true;
            }
            else if (qname.Name != "no")
            {
                builder.SendValidationEvent(SR.Sch_UnknownRequired);
            }

            return fYes;
        }
예제 #21
0
파일: XdrBuilder.cs 프로젝트: dotnet/corefx
        private static void XDR_BuildElementType_Name(XdrBuilder builder, object obj, string prefix)
        {
            XmlQualifiedName qname = (XmlQualifiedName)obj;

            if (builder._SchemaInfo.ElementDecls.ContainsKey(qname))
            {
                builder.SendValidationEvent(SR.Sch_DupElementDecl, XmlQualifiedName.ToString(qname.Name, prefix));
            }
            builder._ElementDef._ElementDecl.Name = qname;
            builder._ElementDef._ElementDecl.Prefix = prefix;
            builder._SchemaInfo.ElementDecls.Add(qname, builder._ElementDef._ElementDecl);
            if (builder._UndeclaredElements[qname] != null)
            {
                builder._UndeclaredElements.Remove(qname);
            }
        }
예제 #22
0
파일: XdrBuilder.cs 프로젝트: dotnet/corefx
        private static uint ParseMinOccurs(object obj, XdrBuilder builder)
        {
            uint cVal = 1;

            if (!ParseInteger((string)obj, ref cVal) || (cVal != 0 && cVal != 1))
            {
                builder.SendValidationEvent(SR.Sch_MinOccursInvalid);
            }
            return cVal;
        }
예제 #23
0
파일: XdrBuilder.cs 프로젝트: dotnet/corefx
 private static void XDR_BuildElementType_Model(XdrBuilder builder, object obj, string prefix)
 {
     builder._contentValidator.IsOpen = builder.GetModel((XmlQualifiedName)obj);
 }
예제 #24
0
파일: XdrBuilder.cs 프로젝트: dotnet/corefx
        private static uint ParseMaxOccurs(object obj, XdrBuilder builder)
        {
            uint cVal = uint.MaxValue;
            string s = (string)obj;

            if (!s.Equals("*") &&
                (!ParseInteger(s, ref cVal) || (cVal != uint.MaxValue && cVal != 1)))
            {
                builder.SendValidationEvent(SR.Sch_MaxOccursInvalid);
            }
            return cVal;
        }
예제 #25
0
파일: XdrBuilder.cs 프로젝트: dotnet/corefx
 private static void XDR_BuildElementType_DtType(XdrBuilder builder, object obj, string prefix)
 {
     builder._ElementDef._HasDataType = true;
     string s = ((string)obj).Trim();
     if (s.Length == 0)
     {
         builder.SendValidationEvent(SR.Sch_MissDtvalue);
     }
     else
     {
         XmlSchemaDatatype dtype = XmlSchemaDatatype.FromXdrName(s);
         if (dtype == null)
         {
             builder.SendValidationEvent(SR.Sch_UnknownDtType, s);
         }
         builder._ElementDef._ElementDecl.Datatype = dtype;
     }
 }
예제 #26
0
파일: XdrBuilder.cs 프로젝트: dotnet/corefx
        private static void ParseDtMinLength(ref uint cVal, object obj, XdrBuilder builder)
        {
            if (uint.MaxValue != cVal)
            {
                builder.SendValidationEvent(SR.Sch_DupDtMinLength);
            }

            if (!ParseInteger((string)obj, ref cVal) || cVal < 0)
            {
                builder.SendValidationEvent(SR.Sch_DtMinLengthInvalid, obj.ToString());
            }
        }
예제 #27
0
파일: XdrBuilder.cs 프로젝트: dotnet/corefx
 private static void XDR_BuildElementType_DtMinLength(XdrBuilder builder, object obj, string prefix)
 {
     ParseDtMinLength(ref builder._ElementDef._MinLength, obj, builder);
 }
예제 #28
0
파일: XdrBuilder.cs 프로젝트: dotnet/corefx
 private static void CompareMinMaxLength(uint cMin, uint cMax, XdrBuilder builder)
 {
     if (cMin != uint.MaxValue && cMax != uint.MaxValue && cMin > cMax)
     {
         builder.SendValidationEvent(SR.Sch_DtMinMaxLength);
     }
 }
예제 #29
0
파일: XdrBuilder.cs 프로젝트: dotnet/corefx
        private static void XDR_EndElementType(XdrBuilder builder)
        {
            SchemaElementDecl ed = builder._ElementDef._ElementDecl;

            // check undefined attribute types first
            if (builder._UndefinedAttributeTypes != null && builder._ElementDef._AttDefList != null)
            {
                DeclBaseInfo patt = builder._UndefinedAttributeTypes;
                DeclBaseInfo p1 = patt;

                while (patt != null)
                {
                    SchemaAttDef pAttdef = null;

                    if (patt._ElementDecl == ed)
                    {
                        XmlQualifiedName pName = patt._TypeName;
                        pAttdef = (SchemaAttDef)builder._ElementDef._AttDefList[pName];
                        if (pAttdef != null)
                        {
                            patt._Attdef = (SchemaAttDef)pAttdef.Clone();
                            patt._Attdef.Name = pName;
                            builder.XDR_CheckAttributeDefault(patt, pAttdef);

                            // remove it from _pUndefinedAttributeTypes
                            if (patt == builder._UndefinedAttributeTypes)
                            {
                                patt = builder._UndefinedAttributeTypes = patt._Next;
                                p1 = patt;
                            }
                            else
                            {
                                p1._Next = patt._Next;
                                patt = p1._Next;
                            }
                        }
                    }

                    if (pAttdef == null)
                    {
                        if (patt != builder._UndefinedAttributeTypes)
                            p1 = p1._Next;
                        patt = patt._Next;
                    }
                }
            }

            if (builder._ElementDef._MasterGroupRequired)
            {
                // if the content is mixed, there is a group that need to be closed
                builder._contentValidator.CloseGroup();

                if (!builder._ElementDef._ExistTerminal)
                {
                    if (builder._contentValidator.IsOpen)
                    {
                        builder._ElementDef._ElementDecl.ContentValidator = ContentValidator.Any;
                        builder._contentValidator = null;
                    }
                    else
                    {
                        if (builder._ElementDef._ContentAttr != SchemaContentMixed)
                            builder.SendValidationEvent(SR.Sch_ElementMissing);
                    }
                }
                else
                {
                    if (builder._GroupDef._Order == SchemaOrderMany)
                    {
                        builder._contentValidator.AddStar();
                    }
                }
            }
            if (ed.Datatype != null)
            {
                XmlTokenizedType ttype = ed.Datatype.TokenizedType;
                if (ttype == XmlTokenizedType.ENUMERATION &&
                    !builder._ElementDef._EnumerationRequired)
                {
                    builder.SendValidationEvent(SR.Sch_MissDtvaluesAttribute);
                }

                if (ttype != XmlTokenizedType.ENUMERATION &&
                    builder._ElementDef._EnumerationRequired)
                {
                    builder.SendValidationEvent(SR.Sch_RequireEnumeration);
                }
            }
            CompareMinMaxLength(builder._ElementDef._MinLength, builder._ElementDef._MaxLength, builder);
            ed.MaxLength = (long)builder._ElementDef._MaxLength;
            ed.MinLength = (long)builder._ElementDef._MinLength;

            if (builder._contentValidator != null)
            {
                builder._ElementDef._ElementDecl.ContentValidator = builder._contentValidator.Finish(true);
                builder._contentValidator = null;
            }

            builder._ElementDef._ElementDecl = null;
            builder._ElementDef._AttDefList = null;
        }
예제 #30
0
파일: XdrBuilder.cs 프로젝트: dotnet/corefx
 //
 // XDR Schema
 //
 private static void XDR_InitRoot(XdrBuilder builder, object obj)
 {
     builder._SchemaInfo.SchemaType = SchemaType.XDR;
     builder._ElementDef._ElementDecl = null;
     builder._ElementDef._AttDefList = null;
     builder._AttributeDef._AttDef = null;
 }