• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Schema.SchemaAttDef类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Xml.Schema.SchemaAttDef的典型用法代码示例。如果您正苦于以下问题:C# SchemaAttDef类的具体用法?C# SchemaAttDef怎么用?C# SchemaAttDef使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SchemaAttDef类属于System.Xml.Schema命名空间,在下文中一共展示了SchemaAttDef类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: CheckDefaultValue

 public static void CheckDefaultValue(string value, SchemaAttDef attdef, SchemaInfo sinfo, XmlNamespaceManager nsManager, XmlNameTable NameTable, object sender, ValidationEventHandler eventhandler, string baseUri, int lineNo, int linePos)
 {
     try
     {
         XmlSchemaDatatype datatype = attdef.Datatype;
         if (datatype != null)
         {
             if (datatype.TokenizedType != XmlTokenizedType.CDATA)
             {
                 value = value.Trim();
             }
             if (value.Length != 0)
             {
                 object pVal = datatype.ParseValue(value, NameTable, nsManager);
                 XmlTokenizedType tokenizedType = datatype.TokenizedType;
                 if (tokenizedType == XmlTokenizedType.ENTITY)
                 {
                     if (datatype.Variety == XmlSchemaDatatypeVariety.List)
                     {
                         string[] strArray = (string[]) pVal;
                         for (int i = 0; i < strArray.Length; i++)
                         {
                             BaseValidator.ProcessEntity(sinfo, strArray[i], sender, eventhandler, baseUri, lineNo, linePos);
                         }
                     }
                     else
                     {
                         BaseValidator.ProcessEntity(sinfo, (string) pVal, sender, eventhandler, baseUri, lineNo, linePos);
                     }
                 }
                 else if ((tokenizedType == XmlTokenizedType.ENUMERATION) && !attdef.CheckEnumeration(pVal))
                 {
                     XmlSchemaException ex = new XmlSchemaException("Sch_EnumerationValue", pVal.ToString(), baseUri, lineNo, linePos);
                     if (eventhandler == null)
                     {
                         throw ex;
                     }
                     eventhandler(sender, new ValidationEventArgs(ex));
                 }
                 attdef.DefaultValueTyped = pVal;
             }
         }
     }
     catch
     {
         XmlSchemaException exception2 = new XmlSchemaException("Sch_AttributeDefaultDataType", attdef.Name.ToString(), baseUri, lineNo, linePos);
         if (eventhandler == null)
         {
             throw exception2;
         }
         eventhandler(sender, new ValidationEventArgs(exception2));
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:53,代码来源:XdrValidator.cs


示例2: AddAttDef

 // add a new SchemaAttDef to the SchemaElementDecl
 internal void AddAttDef(SchemaAttDef attdef)
 {
     _attdefs.Add(attdef.Name, attdef);
     if (attdef.Presence == SchemaDeclBase.Use.Default || attdef.Presence == SchemaDeclBase.Use.Fixed)
     { //Not adding RequiredFixed here
         if (_defaultAttdefs == null)
         {
             _defaultAttdefs = new List<IDtdDefaultAttributeInfo>();
         }
         _defaultAttdefs.Add(attdef);
     }
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:13,代码来源:SchemaElementDecl.cs


示例3: AddAttDef

 internal void AddAttDef(SchemaAttDef attdef)
 {
     this.attdefs.Add(attdef.Name, attdef);
     if ((attdef.Presence == SchemaDeclBase.Use.Required) || (attdef.Presence == SchemaDeclBase.Use.RequiredFixed))
     {
         this.hasRequiredAttribute = true;
     }
     if ((attdef.Presence == SchemaDeclBase.Use.Default) || (attdef.Presence == SchemaDeclBase.Use.Fixed))
     {
         if (this.defaultAttdefs == null)
         {
             this.defaultAttdefs = new List<IDtdDefaultAttributeInfo>();
         }
         this.defaultAttdefs.Add(attdef);
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:16,代码来源:SchemaElementDecl.cs


示例4: CheckDefaultValue

 public static void CheckDefaultValue(SchemaAttDef attdef, SchemaInfo sinfo, IValidationEventHandling eventHandling, string baseUriStr)
 {
     try
     {
         if (baseUriStr == null)
         {
             baseUriStr = string.Empty;
         }
         XmlSchemaDatatype datatype = attdef.Datatype;
         if (datatype != null)
         {
             object defaultValueTyped = attdef.DefaultValueTyped;
             XmlTokenizedType tokenizedType = datatype.TokenizedType;
             if (tokenizedType == XmlTokenizedType.ENTITY)
             {
                 if (datatype.Variety == XmlSchemaDatatypeVariety.List)
                 {
                     string[] strArray = (string[]) defaultValueTyped;
                     for (int i = 0; i < strArray.Length; i++)
                     {
                         BaseValidator.ProcessEntity(sinfo, strArray[i], eventHandling, baseUriStr, attdef.ValueLineNumber, attdef.ValueLinePosition);
                     }
                 }
                 else
                 {
                     BaseValidator.ProcessEntity(sinfo, (string) defaultValueTyped, eventHandling, baseUriStr, attdef.ValueLineNumber, attdef.ValueLinePosition);
                 }
             }
             else if (((tokenizedType == XmlTokenizedType.ENUMERATION) && !attdef.CheckEnumeration(defaultValueTyped)) && (eventHandling != null))
             {
                 XmlSchemaException exception = new XmlSchemaException("Sch_EnumerationValue", defaultValueTyped.ToString(), baseUriStr, attdef.ValueLineNumber, attdef.ValueLinePosition);
                 eventHandling.SendEvent(exception, XmlSeverityType.Error);
             }
         }
     }
     catch (Exception)
     {
         if (eventHandling != null)
         {
             XmlSchemaException exception2 = new XmlSchemaException("Sch_AttributeDefaultDataType", attdef.Name.ToString());
             eventHandling.SendEvent(exception2, XmlSeverityType.Error);
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:44,代码来源:DtdValidator.cs


示例5: XDR_BeginAttribute

        private static void XDR_BeginAttribute(XdrBuilder builder)
        {
            if (builder._BaseDecl._TypeName.IsEmpty)
            {
                builder.SendValidationEvent(SR.Sch_MissAttribute);
            }

            SchemaAttDef attdef = null;
            XmlQualifiedName qname = builder._BaseDecl._TypeName;
            string prefix = builder._BaseDecl._Prefix;

            // local?
            if (builder._ElementDef._AttDefList != null)
            {
                attdef = (SchemaAttDef)builder._ElementDef._AttDefList[qname];
            }

            // global?
            if (attdef == null)
            {
                // 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.
                XmlQualifiedName gname = qname;
                if (prefix.Length == 0)
                    gname = new XmlQualifiedName(qname.Name, builder._TargetNamespace);
                SchemaAttDef ad;
                if (builder._SchemaInfo.AttributeDecls.TryGetValue(gname, out ad))
                {
                    attdef = (SchemaAttDef)ad.Clone();
                    attdef.Name = qname;
                }
                else if (prefix.Length != 0)
                {
                    builder.SendValidationEvent(SR.Sch_UndeclaredAttribute, XmlQualifiedName.ToString(qname.Name, prefix));
                }
            }

            if (attdef != null)
            {
                builder.XDR_CheckAttributeDefault(builder._BaseDecl, attdef);
            }
            else
            {
                // will process undeclared types later
                attdef = new SchemaAttDef(qname, prefix);
                DeclBaseInfo decl = new DeclBaseInfo();
                decl._Checking = true;
                decl._Attdef = attdef;
                decl._TypeName = builder._BaseDecl._TypeName;
                decl._ElementDecl = builder._ElementDef._ElementDecl;
                decl._MinOccurs = builder._BaseDecl._MinOccurs;
                decl._Default = builder._BaseDecl._Default;

                // add undefined attribute types
                decl._Next = builder._UndefinedAttributeTypes;
                builder._UndefinedAttributeTypes = decl;
            }

            builder._ElementDef._ElementDecl.AddAttDef(attdef);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:61,代码来源:XdrBuilder.cs


示例6: AddDefaultAttributeNonDtd

        internal bool AddDefaultAttributeNonDtd(SchemaAttDef attrDef)
        {
            // atomize names - Xsd Validator does not need to have the same nametable
            string localName = _nameTable.Add(attrDef.Name.Name);
            string prefix = _nameTable.Add(attrDef.Prefix);
            string ns = _nameTable.Add(attrDef.Name.Namespace);

            // atomize namespace - Xsd Validator does not need to have the same nametable
            if (prefix.Length == 0 && ns.Length > 0)
            {
                prefix = _namespaceManager.LookupPrefix(ns);

                Debug.Assert(prefix != null);
                if (prefix == null)
                {
                    prefix = string.Empty;
                }
            }

            // find out if the attribute is already there
            for (int i = _index + 1; i < _index + 1 + _attrCount; i++)
            {
                if ((object)_nodes[i].localName == (object)localName &&
                    (((object)_nodes[i].prefix == (object)prefix) || ((object)_nodes[i].ns == (object)ns && ns != null)))
                {
                    return false;
                }
            }

            // attribute does not exist -> we need to add it
            NodeData attr = AddDefaultAttributeInternal(localName, ns, prefix, attrDef.DefaultValueExpanded,
                                                         attrDef.LineNumber, attrDef.LinePosition,
                                                         attrDef.ValueLineNumber, attrDef.ValueLinePosition, attrDef.Reserved != SchemaAttDef.Reserve.None);
            Debug.Assert(attr != null);

            attr.schemaType = (attrDef.SchemaType == null) ? (object)attrDef.Datatype : (object)attrDef.SchemaType;
            attr.typedValue = attrDef.DefaultValueTyped;
            return true;
        }
开发者ID:chcosta,项目名称:corefx,代码行数:39,代码来源:XmlTextReaderImpl.cs


示例7: ValidateAttribute

        private object ValidateAttribute(string lName, string ns, XmlValueGetter attributeValueGetter, string attributeStringValue, XmlSchemaInfo schemaInfo)
        {
            if (lName == null)
            {
                throw new ArgumentNullException("localName");
            }
            if (ns == null)
            {
                throw new ArgumentNullException("namespaceUri");
            }
            ValidatorState toState = (this.validationStack.Length > 1) ? ValidatorState.Attribute : ValidatorState.TopLevelAttribute;
            this.CheckStateTransition(toState, MethodNames[(int) toState]);
            object typedValue = null;
            this.attrValid = true;
            XmlSchemaValidity notKnown = XmlSchemaValidity.NotKnown;
            XmlSchemaAttribute schemaAttribute = null;
            XmlSchemaSimpleType xmlType = null;
            ns = this.nameTable.Add(ns);
            if (Ref.Equal(ns, this.NsXmlNs))
            {
                return null;
            }
            SchemaAttDef def = null;
            SchemaElementDecl elementDecl = this.context.ElementDecl;
            XmlQualifiedName key = new XmlQualifiedName(lName, ns);
            if (this.attPresence[key] != null)
            {
                this.SendValidationEvent("Sch_DuplicateAttribute", key.ToString());
                if (schemaInfo != null)
                {
                    schemaInfo.Clear();
                }
                return null;
            }
            if (Ref.Equal(ns, this.NsXsi))
            {
                lName = this.nameTable.Add(lName);
                if ((Ref.Equal(lName, this.xsiTypeString) || Ref.Equal(lName, this.xsiNilString)) || (Ref.Equal(lName, this.xsiSchemaLocationString) || Ref.Equal(lName, this.xsiNoNamespaceSchemaLocationString)))
                {
                    this.attPresence.Add(key, SchemaAttDef.Empty);
                }
                else
                {
                    this.attrValid = false;
                    this.SendValidationEvent("Sch_NotXsiAttribute", key.ToString());
                }
            }
            else
            {
                AttributeMatchState state2;
                object obj4;
                XmlSchemaObject partialValidationType = (this.currentState == ValidatorState.TopLevelAttribute) ? this.partialValidationType : null;
                def = this.compiledSchemaInfo.GetAttributeXsd(elementDecl, key, partialValidationType, out state2);
                switch (state2)
                {
                    case AttributeMatchState.AttributeFound:
                        break;

                    case AttributeMatchState.AnyIdAttributeFound:
                        if (this.wildID != null)
                        {
                            this.SendValidationEvent("Sch_MoreThanOneWildId", string.Empty);
                        }
                        else
                        {
                            this.wildID = def;
                            XmlSchemaComplexType schemaType = elementDecl.SchemaType as XmlSchemaComplexType;
                            if (!schemaType.ContainsIdAttribute(false))
                            {
                                break;
                            }
                            this.SendValidationEvent("Sch_AttrUseAndWildId", string.Empty);
                        }
                        goto Label_0409;

                    case AttributeMatchState.UndeclaredElementAndAttribute:
                        def = this.CheckIsXmlAttribute(key);
                        if (def != null)
                        {
                            break;
                        }
                        if (((elementDecl != null) || (this.processContents != XmlSchemaContentProcessing.Strict)) || ((key.Namespace.Length == 0) || !this.compiledSchemaInfo.Contains(key.Namespace)))
                        {
                            if (this.processContents != XmlSchemaContentProcessing.Skip)
                            {
                                this.SendValidationEvent("Sch_NoAttributeSchemaFound", key.ToString(), XmlSeverityType.Warning);
                            }
                        }
                        else
                        {
                            this.attrValid = false;
                            this.SendValidationEvent("Sch_UndeclaredAttribute", key.ToString());
                        }
                        goto Label_0409;

                    case AttributeMatchState.UndeclaredAttribute:
                        def = this.CheckIsXmlAttribute(key);
                        if (def != null)
                        {
                            break;
//.........这里部分代码省略.........
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:101,代码来源:XmlSchemaValidator.cs


示例8: CheckAttributeValue

 private object CheckAttributeValue(object value, SchemaAttDef attdef)
 {
     object typedValue = null;
     SchemaDeclBase decl = attdef;
     XmlSchemaDatatype datatype = attdef.Datatype;
     string s = value as string;
     Exception innerException = null;
     if (s != null)
     {
         innerException = datatype.TryParseValue(s, this.nameTable, this.nsResolver, out typedValue);
         if (innerException == null)
         {
             goto Label_0050;
         }
         goto Label_0078;
     }
     innerException = datatype.TryParseValue(value, this.nameTable, this.nsResolver, out typedValue);
     if (innerException != null)
     {
         goto Label_0078;
     }
 Label_0050:
     if (!decl.CheckValue(typedValue))
     {
         this.attrValid = false;
         this.SendValidationEvent("Sch_FixedAttributeValue", attdef.Name.ToString());
     }
     return typedValue;
 Label_0078:
     this.attrValid = false;
     if (s == null)
     {
         s = XmlSchemaDatatype.ConcatenatedToString(value);
     }
     this.SendValidationEvent("Sch_AttributeValueDataTypeDetailed", new string[] { attdef.Name.ToString(), s, this.GetTypeName(decl), innerException.Message }, innerException);
     return null;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:37,代码来源:XmlSchemaValidator.cs


示例9: CheckDefaultAttValue

 private void CheckDefaultAttValue(SchemaAttDef attDef)
 {
     string str = (attDef.DefaultValueRaw).Trim();
     XdrValidator.CheckDefaultValue(str, attDef, _SchemaInfo, _CurNsMgr, _NameTable, null, _validationEventHandler, _reader.BaseURI, _positionInfo.LineNumber, _positionInfo.LinePosition);
 }
开发者ID:dotnet,项目名称:corefx,代码行数:5,代码来源:XdrBuilder.cs


示例10: ParseAttlistDeclAsync

        private async Task ParseAttlistDeclAsync() {
            if (await GetTokenAsync(true).ConfigureAwait(false) != Token.QName) {
                goto UnexpectedError;
            }

            // element name
            XmlQualifiedName elementName = GetNameQualified(true);
            SchemaElementDecl elementDecl;
            if (!schemaInfo.ElementDecls.TryGetValue(elementName, out elementDecl)) {
                if (!schemaInfo.UndeclaredElementDecls.TryGetValue(elementName, out elementDecl)) {
                    elementDecl = new SchemaElementDecl(elementName, elementName.Namespace);
                    schemaInfo.UndeclaredElementDecls.Add(elementName, elementDecl);
                }
            }

            SchemaAttDef attrDef = null;
            for (; ; ) {
                switch (await GetTokenAsync(false).ConfigureAwait(false)) {
                    case Token.QName:
                        XmlQualifiedName attrName = GetNameQualified(true);
                        attrDef = new SchemaAttDef(attrName, attrName.Namespace);
                        attrDef.IsDeclaredInExternal = !ParsingInternalSubset;
                        attrDef.LineNumber = (int)LineNo;
                        attrDef.LinePosition = (int)LinePos - (curPos - tokenStartPos);
                        break;
                    case Token.GreaterThan:
#if !SILVERLIGHT
                        if ( v1Compat ) {
                            // check xml:space and xml:lang
                            // 


                            if ( attrDef != null && attrDef.Prefix.Length > 0 && attrDef.Prefix.Equals( "xml" ) && attrDef.Name.Name == "space" ) {
                                attrDef.Reserved = SchemaAttDef.Reserve.XmlSpace;
                                if ( attrDef.Datatype.TokenizedType != XmlTokenizedType.ENUMERATION ) {
                                    Throw( Res.Xml_EnumerationRequired, string.Empty, attrDef.LineNumber, attrDef.LinePosition );
                                }
                                if ( validate ) {
                                    attrDef.CheckXmlSpace( readerAdapterWithValidation.ValidationEventHandling );
                                }
                            }
                        }
#endif
                        return;
                    default:
                        goto UnexpectedError;
                }

                bool attrDefAlreadyExists = (elementDecl.GetAttDef(attrDef.Name) != null);

                await ParseAttlistTypeAsync(attrDef, elementDecl, attrDefAlreadyExists).ConfigureAwait(false);
                await ParseAttlistDefaultAsync(attrDef, attrDefAlreadyExists).ConfigureAwait(false);

                // check xml:space and xml:lang
                if (attrDef.Prefix.Length > 0 && attrDef.Prefix.Equals("xml")) {
                    if ( attrDef.Name.Name == "space" ) {
#if !SILVERLIGHT
                        if ( v1Compat ) {
                            // 



                            string val = attrDef.DefaultValueExpanded.Trim();
                            if ( val.Equals( "preserve" ) || val.Equals( "default" ) ) {
                                attrDef.Reserved = SchemaAttDef.Reserve.XmlSpace;
                            }
                        }
                        else {
#endif
                            attrDef.Reserved = SchemaAttDef.Reserve.XmlSpace;
                            if ( attrDef.TokenizedType != XmlTokenizedType.ENUMERATION ) {
                                Throw( Res.Xml_EnumerationRequired, string.Empty, attrDef.LineNumber, attrDef.LinePosition );
                            }
#if !SILVERLIGHT
                            if ( validate ) {
                                attrDef.CheckXmlSpace( readerAdapterWithValidation.ValidationEventHandling );
                            }
                        }
#endif
                    }
                    else if ( attrDef.Name.Name == "lang" ) {
                        attrDef.Reserved = SchemaAttDef.Reserve.XmlLang;
                    }
                }

                // add attribute to element decl
                if (!attrDefAlreadyExists) {
                    elementDecl.AddAttDef(attrDef);
                }
            }

        UnexpectedError:
            OnUnexpectedError();
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:94,代码来源:DtdParserAsync.cs


示例11: ParseAttlistDecl

        private void ParseAttlistDecl()
        {
            if (GetToken(true) != Token.QName)
            {
                goto UnexpectedError;
            }

            // element name
            XmlQualifiedName elementName = GetNameQualified(true);
            SchemaElementDecl elementDecl;
            if (!_schemaInfo.ElementDecls.TryGetValue(elementName, out elementDecl))
            {
                if (!_schemaInfo.UndeclaredElementDecls.TryGetValue(elementName, out elementDecl))
                {
                    elementDecl = new SchemaElementDecl(elementName, elementName.Namespace);
                    _schemaInfo.UndeclaredElementDecls.Add(elementName, elementDecl);
                }
            }

            SchemaAttDef attrDef = null;
            for (;;)
            {
                switch (GetToken(false))
                {
                    case Token.QName:
                        XmlQualifiedName attrName = GetNameQualified(true);
                        attrDef = new SchemaAttDef(attrName, attrName.Namespace);
                        attrDef.IsDeclaredInExternal = !ParsingInternalSubset;
                        attrDef.LineNumber = (int)LineNo;
                        attrDef.LinePosition = (int)LinePos - (_curPos - _tokenStartPos);
                        break;
                    case Token.GreaterThan:
#if !SILVERLIGHT
                        if (_v1Compat)
                        {
                            // check xml:space and xml:lang
                            // BUG BUG: For backward compatibility, we check the correct type and values of the
                            // xml:space attribute only on the last attribute in the list.
                            // See Webdata bugs #97457 and #93935.
                            if (attrDef != null && attrDef.Prefix.Length > 0 && attrDef.Prefix.Equals("xml") && attrDef.Name.Name == "space")
                            {
                                attrDef.Reserved = SchemaAttDef.Reserve.XmlSpace;
                                if (attrDef.Datatype.TokenizedType != XmlTokenizedType.ENUMERATION)
                                {
                                    Throw(SR.Xml_EnumerationRequired, string.Empty, attrDef.LineNumber, attrDef.LinePosition);
                                }
                                if (_validate)
                                {
                                    attrDef.CheckXmlSpace(_readerAdapterWithValidation.ValidationEventHandling);
                                }
                            }
                        }
#endif
                        return;
                    default:
                        goto UnexpectedError;
                }

                bool attrDefAlreadyExists = (elementDecl.GetAttDef(attrDef.Name) != null);

                ParseAttlistType(attrDef, elementDecl, attrDefAlreadyExists);
                ParseAttlistDefault(attrDef, attrDefAlreadyExists);

                // check xml:space and xml:lang
                if (attrDef.Prefix.Length > 0 && attrDef.Prefix.Equals("xml"))
                {
                    if (attrDef.Name.Name == "space")
                    {
#if !SILVERLIGHT
                        if (_v1Compat)
                        {
                            // BUG BUG: For backward compatibility, we check the correct type and values of the
                            // xml:space attribute only on the last attribute in the list, and mark it as reserved 
                            // only its value is correct (=prevent XmlTextReader from fhrowing on invalid value). 
                            // See Webdata bugs #98168, #97457 and #93935.
                            string val = attrDef.DefaultValueExpanded.Trim();
                            if (val.Equals("preserve") || val.Equals("default"))
                            {
                                attrDef.Reserved = SchemaAttDef.Reserve.XmlSpace;
                            }
                        }
                        else
                        {
#endif
                            attrDef.Reserved = SchemaAttDef.Reserve.XmlSpace;
                            if (attrDef.TokenizedType != XmlTokenizedType.ENUMERATION)
                            {
                                Throw(SR.Xml_EnumerationRequired, string.Empty, attrDef.LineNumber, attrDef.LinePosition);
                            }
#if !SILVERLIGHT
                            if (_validate)
                            {
                                attrDef.CheckXmlSpace(_readerAdapterWithValidation.ValidationEventHandling);
                            }
                        }
#endif
                    }
                    else if (attrDef.Name.Name == "lang")
                    {
                        attrDef.Reserved = SchemaAttDef.Reserve.XmlLang;
//.........这里部分代码省略.........
开发者ID:chcosta,项目名称:corefx,代码行数:101,代码来源:DtdParser.cs


示例12: ParseAttlistDefault

        private void ParseAttlistDefault(SchemaAttDef attrDef, bool ignoreErrors)
        {
            switch (GetToken(true))
            {
                case Token.REQUIRED:
                    attrDef.Presence = SchemaDeclBase.Use.Required;
                    return;
                case Token.IMPLIED:
                    attrDef.Presence = SchemaDeclBase.Use.Implied;
                    return;
                case Token.FIXED:
                    attrDef.Presence = SchemaDeclBase.Use.Fixed;
                    if (GetToken(true) != Token.Literal)
                    {
                        goto UnexpectedError;
                    }
                    break;
                case Token.Literal:
                    break;
                default:
                    goto UnexpectedError;
            }

#if !SILVERLIGHT
            if (_validate && attrDef.Datatype.TokenizedType == XmlTokenizedType.ID && !ignoreErrors)
            {
                SendValidationEvent(_curPos, XmlSeverityType.Error, SR.Sch_AttListPresence, string.Empty);
            }
#endif

            if (attrDef.TokenizedType != XmlTokenizedType.CDATA)
            {
                // non-CDATA attribute type normalization - strip spaces
                attrDef.DefaultValueExpanded = GetValueWithStrippedSpaces();
            }
            else
            {
                attrDef.DefaultValueExpanded = GetValue();
            }
            attrDef.ValueLineNumber = (int)_literalLineInfo.lineNo;
            attrDef.ValueLinePosition = (int)_literalLineInfo.linePos + 1;

#if !SILVERLIGHT
            DtdValidator.SetDefaultTypedValue(attrDef, _readerAdapter);
#endif
            return;

        UnexpectedError:
            OnUnexpectedError();
        }
开发者ID:chcosta,项目名称:corefx,代码行数:50,代码来源:DtdParser.cs


示例13: CheckValue

        private void CheckValue(
            string              value,
            SchemaAttDef        attdef
        ) {
            try {
                reader.TypedValueObject = null;
                bool isAttn = attdef != null;
                XmlSchemaDatatype dtype = isAttn ? attdef.Datatype : context.ElementDecl.Datatype;
                if (dtype == null) {
                    return; // no reason to check
                }
                
                if (dtype.TokenizedType != XmlTokenizedType.CDATA) {
                    value = value.Trim();
                }
                if (value.Length == 0) {
                    return; // don't need to check
                }
            

                object typedValue = dtype.ParseValue(value, NameTable, nsManager);
                reader.TypedValueObject = typedValue;
                // Check special types
                XmlTokenizedType ttype = dtype.TokenizedType;
                if (ttype == XmlTokenizedType.ENTITY || ttype == XmlTokenizedType.ID || ttype == XmlTokenizedType.IDREF) {
                    if (dtype.Variety == XmlSchemaDatatypeVariety.List) {
                        string[] ss = (string[])typedValue;
                        for (int i = 0; i < ss.Length; ++i) {
                            ProcessTokenizedType(dtype.TokenizedType, ss[i]);
                        }
                    }
                    else {
                        ProcessTokenizedType(dtype.TokenizedType, (string)typedValue);
                    }
                }

                SchemaDeclBase decl = isAttn ? (SchemaDeclBase)attdef : (SchemaDeclBase)context.ElementDecl;

                if (decl.MaxLength != uint.MaxValue) {
                    if(value.Length > decl.MaxLength) {
                        SendValidationEvent(Res.Sch_MaxLengthConstraintFailed, value);
                    }
                }
                if (decl.MinLength != uint.MaxValue) {
                    if(value.Length < decl.MinLength) {
                        SendValidationEvent(Res.Sch_MinLengthConstraintFailed, value);
                    }
                }
                if (decl.Values != null && !decl.CheckEnumeration(typedValue)) {
                    if (dtype.TokenizedType == XmlTokenizedType.NOTATION) {
                        SendValidationEvent(Res.Sch_NotationValue, typedValue.ToString());
                    }
                    else {
                        SendValidationEvent(Res.Sch_EnumerationValue, typedValue.ToString());
                    }

                }
                if (!decl.CheckValue(typedValue)) {
                    if (isAttn) {
                        SendValidationEvent(Res.Sch_FixedAttributeValue, attdef.Name.ToString());
                    }
                    else {
                        SendValidationEvent(Res.Sch_FixedElementValue, XmlSchemaValidator.QNameString(context.LocalName, context.Namespace));
                    }
                }
            }
            catch (XmlSchemaException) {
                if (attdef != null) {
                    SendValidationEvent(Res.Sch_AttributeValueDataType, attdef.Name.ToString());
                }
                else {
                    SendValidationEvent(Res.Sch_ElementValueDataType, XmlSchemaValidator.QNameString(context.LocalName, context.Namespace));
                }
            }
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:75,代码来源:xdrvalidator.cs


示例14: CheckDefaultValue

        public static void CheckDefaultValue(
            string              value,
            SchemaAttDef        attdef,
            SchemaInfo          sinfo,
            XmlNamespaceManager     nsManager,
            XmlNameTable        NameTable,
            object              sender,
            ValidationEventHandler  eventhandler,
            string              baseUri,
            int                 lineNo,
            int                 linePos
        ) {
            try {

                XmlSchemaDatatype dtype = attdef.Datatype;
                if (dtype == null) {
                    return; // no reason to check
                }
                
                if (dtype.TokenizedType != XmlTokenizedType.CDATA) {
                    value = value.Trim();
                }
                if (value.Length == 0) {
                    return; // don't need to check
                }
                object typedValue = dtype.ParseValue(value, NameTable, nsManager);

                // Check special types
                XmlTokenizedType ttype = dtype.TokenizedType;
                if (ttype == XmlTokenizedType.ENTITY) {
                    if (dtype.Variety == XmlSchemaDatatypeVariety.List) {
                        string[] ss = (string[])typedValue;
                        for (int i = 0; i < ss.Length; ++i) {
                            ProcessEntity(sinfo, ss[i], sender, eventhandler, baseUri, lineNo, linePos);
                        }
                    }
                    else {
                        ProcessEntity(sinfo, (string)typedValue, sender, eventhandler, baseUri, lineNo, linePos);
                    }
                }
                else if (ttype == XmlTokenizedType.ENUMERATION) {
                    if (!attdef.CheckEnumeration(typedValue)) {
                        XmlSchemaException e = new XmlSchemaException(Res.Sch_EnumerationValue, typedValue.ToString(), baseUri, lineNo, linePos);
                        if (eventhandler != null) {
                            eventhandler(sender, new ValidationEventArgs(e));
                        }
                        else {
                            throw e;
                        }
                    }
                }
                attdef.DefaultValueTyped = typedValue;
            }
#if DEBUG
            catch (XmlSchemaException ex) {
                Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceError, ex.Message);
#else
            catch  {
#endif
                XmlSchemaException e = new XmlSchemaException(Res.Sch_AttributeDefaultDataType, attdef.Name.ToString(), baseUri, lineNo, linePos);
                if (eventhandler != null) {
                    eventhandler(sender, new ValidationEventArgs(e));
                }
                else {
                    throw e;
                }
            }
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:68,代码来源:xdrvalidator.cs


示例15: ValidateAttribute

        private object ValidateAttribute(string lName, string ns, XmlValueGetter attributeValueGetter, string attributeStringValue, XmlSchemaInfo schemaInfo) {
            if (lName == null) {
                throw new ArgumentNullException("localName");
            }
            if (ns == null) {
                throw new ArgumentNullException("namespaceUri");
            }

            ValidatorState toState = validationStack.Length > 1 ? ValidatorState.Attribute : ValidatorState.TopLevelAttribute;
            CheckStateTransition(toState, MethodNames[(int)toState]);

            object typedVal = null;
            attrValid = true;
            XmlSchemaValidity localValidity = XmlSchemaValidity.NotKnown;
            XmlSchemaAttribute localAttribute = null;
            XmlSchemaSimpleType localMemberType = null;

            ns = nameTable.Add(ns);
            if(Ref.Equal(ns,NsXmlNs)) {
                return null;
            }

            SchemaAttDef attributeDef = null;
            SchemaElementDecl currentElementDecl = context.ElementDecl;
            XmlQualifiedName attQName = new XmlQualifiedName(lName, ns);
            if (attPresence[attQName] != null) { //this attribute already checked as it is duplicate;
                SendValidationEvent(Res.Sch_DuplicateAttribute, attQName.ToString());
                if (schemaInfo != null) {
                    schemaInfo.Clear();
                }
                return null;
            }

            if (!Ref.Equal(ns,NsXsi)) { //
                XmlSchemaObject pvtAttribute = currentState == ValidatorState.TopLevelAttribute ? partialValidationType : null;
                AttributeMatchState attributeMatchState;
                attributeDef = compiledSchemaInfo.GetAttributeXsd(currentElementDecl, attQName, pvtAttribute, out attributeMatchState);

                switch (attributeMatchState) {
                    case AttributeMatchState.UndeclaredElementAndAttribute:
                        if((attributeDef = CheckIsXmlAttribute(attQName)) != null) { //Try for xml attribute
                            goto case AttributeMatchState.AttributeFound;
                        }
                        if (currentElementDecl == null
                            && processContents == XmlSchemaContentProcessing.Strict
                            && attQName.Namespace.Length != 0
                            && compiledSchemaInfo.Contains(attQName.Namespace)
                        ) {
                            attrValid = false;
                            SendValidationEvent(Res.Sch_UndeclaredAttribute, attQName.ToString());
                        }
                        else if (processContents != XmlSchemaContentProcessing.Skip) {
                            SendValidationEvent(Res.Sch_NoAttributeSchemaFound, attQName.ToString(), XmlSeverityType.Warning);
                        }
                        break;

                    case AttributeMatchState.UndeclaredAttribute:
                        if((attributeDef = CheckIsXmlAttribute(attQName)) != null) {
                            goto case AttributeMatchState.AttributeFound;
                        }
                        else {
                            attrValid = false;
                            SendValidationEvent(Res.Sch_UndeclaredAttribute, attQName.ToString());
                        }
                        break;

                    case AttributeMatchState.ProhibitedAnyAttribute:
                        if((attributeDef = CheckIsXmlAttribute(attQName)) != null) {
                            goto case AttributeMatchState.AttributeFound;
                        }
                        else {
                            attrValid = false;
                            SendValidationEvent(Res.Sch_ProhibitedAttribute, attQName.ToString());
                        }
                        break;

                    case AttributeMatchState.ProhibitedAttribute:
                        attrValid = false;
                        SendValidationEvent(Res.Sch_ProhibitedAttribute, attQName.ToString());
                        break;

                    case AttributeMatchState.AttributeNameMismatch:
                        attrValid = false;
                        SendValidationEvent(Res.Sch_SchemaAttributeNameMismatch, new string[] { attQName.ToString(), ((XmlSchemaAttribute)pvtAttribute).QualifiedName.ToString()});
                        break;

                    case AttributeMatchState.ValidateAttributeInvalidCall:
                        Debug.Assert(currentState == ValidatorState.TopLevelAttribute); //Re-set state back to start on error with partial validation type
                        currentState = ValidatorState.Start;
                        attrValid = false;
                        SendValidationEvent(Res.Sch_ValidateAttributeInvalidCall, string.Empty);
                        break;

                    case AttributeMatchState.AnyIdAttributeFound:
                        if (wildID == null) {
                            wildID = attributeDef;
                            Debug.Assert(currentElementDecl != null);
                            XmlSchemaComplexType ct = currentElementDecl.SchemaType as XmlSchemaComplexType;
                            Debug.Assert(ct != null);
                            if (ct.ContainsIdAttribute(false)) {
//.........这里部分代码省略.........
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:101,代码来源:XmlSchemaValidator.cs


示例16: CheckAttributeValue

        private object CheckAttributeValue(object value, SchemaAttDef attdef) {
            object typedValue = null;
            SchemaDeclBase decl = attdef as SchemaDeclBase;

            XmlSchemaDatatype dtype = attdef.Datatype;
            Debug.Assert(dtype != null);
            string stringValue = value as string;
            Exception exception = null;

            if (stringValue != null) { //
                exception = dtype.TryParseValue(stringValue, nameTable, nsResolver, out typedValue);
                if (exception != null) goto Error;
            }
            else { //Calling object ParseValue for checking facets
                exception = dtype.TryParseValue(value, nameTable, nsResolver, out typedValue);
                if (exception != null) goto Error;
            }
            if (!decl.CheckValue(typedValue)) {
                attrValid = false;
                SendValidationEvent(Res.Sch_FixedAttributeValue, attdef.Name.ToString());
            }
            return typedValue;

        Error:
            attrValid = false;
            if (stringValue == null) {
                stringValue = XmlSchemaDatatype.ConcatenatedToString(value);
            }
            SendValidationEvent(Res.Sch_AttributeValueDataTypeDetailed, new string[] { attdef.Name.ToString(), stringValue, GetTypeName(decl), exception.Message }, exception);
            return null;
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:31,代码来源:XmlSchemaValidator.cs


示例17: XDR_CheckAttributeDefault


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Schema.SchemaInfo类代码示例发布时间:2022-05-26
下一篇:
C# Schema.BitSet类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap