GetAttDef() public méthode

public GetAttDef ( XmlQualifiedName qname ) : SchemaAttDef
qname System.Xml.XmlQualifiedName
Résultat SchemaAttDef
        internal SchemaAttDef GetAttributeXdr(SchemaElementDecl ed, XmlQualifiedName qname)
        {
            SchemaAttDef attdef = null;

            if (ed != null)
            {
                attdef = ed.GetAttDef(qname);;
                if (attdef == null)
                {
                    if (!ed.ContentValidator.IsOpen || qname.Namespace.Length == 0)
                    {
                        throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, qname.ToString());
                    }
                    if (!attributeDecls.TryGetValue(qname, out attdef) && targetNamespaces.ContainsKey(qname.Namespace))
                    {
                        throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, qname.ToString());
                    }
                }
            }
            return(attdef);
        }
Exemple #2
0
        private void ParseAttlistType(SchemaAttDef attrDef, SchemaElementDecl elementDecl, bool ignoreErrors)
        {
            Token token = GetToken(true);

            if (token != Token.CDATA)
            {
                elementDecl.HasNonCDataAttribute = true;
            }

            if (IsAttributeValueType(token))
            {
                attrDef.TokenizedType = (XmlTokenizedType)(int)token;
#if !SILVERLIGHT
                attrDef.SchemaType = XmlSchemaType.GetBuiltInSimpleType(attrDef.Datatype.TypeCode);
#endif

                switch (token)
                {
                    case Token.NOTATION:
                        break;
                    case Token.ID:
#if !SILVERLIGHT
                        if (_validate && elementDecl.IsIdDeclared)
                        {
                            SchemaAttDef idAttrDef = elementDecl.GetAttDef(attrDef.Name);
                            if ((idAttrDef == null || idAttrDef.Datatype.TokenizedType != XmlTokenizedType.ID) && !ignoreErrors)
                            {
                                SendValidationEvent(XmlSeverityType.Error, SR.Sch_IdAttrDeclared, elementDecl.Name.ToString());
                            }
                        }
#endif
                        elementDecl.IsIdDeclared = true;
                        return;
                    default:
                        return;
                }
#if !SILVERLIGHT
                // check notation constrains
                if (_validate)
                {
                    if (elementDecl.IsNotationDeclared && !ignoreErrors)
                    {
                        SendValidationEvent(_curPos - 8, XmlSeverityType.Error, SR.Sch_DupNotationAttribute, elementDecl.Name.ToString()); // 8 == strlen("NOTATION")
                    }
                    else
                    {
                        if (elementDecl.ContentValidator != null &&
                            elementDecl.ContentValidator.ContentType == XmlSchemaContentType.Empty &&
                            !ignoreErrors)
                        {
                            SendValidationEvent(_curPos - 8, XmlSeverityType.Error, SR.Sch_NotationAttributeOnEmptyElement, elementDecl.Name.ToString());// 8 == strlen("NOTATION")
                        }
                        elementDecl.IsNotationDeclared = true;
                    }
                }
#endif

                if (GetToken(true) != Token.LeftParen)
                {
                    goto UnexpectedError;
                }

                // parse notation list
                if (GetToken(false) != Token.Name)
                {
                    goto UnexpectedError;
                }
                for (;;)
                {
                    string notationName = GetNameString();
#if !SILVERLIGHT
                    if (!_schemaInfo.Notations.ContainsKey(notationName))
                    {
                        AddUndeclaredNotation(notationName);
                    }
                    if (_validate && !_v1Compat && attrDef.Values != null && attrDef.Values.Contains(notationName) && !ignoreErrors)
                    {
                        SendValidationEvent(XmlSeverityType.Error, new XmlSchemaException(SR.Xml_AttlistDuplNotationValue, notationName, BaseUriStr, (int)LineNo, (int)LinePos));
                    }
                    attrDef.AddValue(notationName);
#endif

                    switch (GetToken(false))
                    {
                        case Token.Or:
                            if (GetToken(false) != Token.Name)
                            {
                                goto UnexpectedError;
                            }
                            continue;
                        case Token.RightParen:
                            return;
                        default:
                            goto UnexpectedError;
                    }
                }
            }
            else if (token == Token.LeftParen)
            {
                attrDef.TokenizedType = XmlTokenizedType.ENUMERATION;
#if !SILVERLIGHT
                attrDef.SchemaType = XmlSchemaType.GetBuiltInSimpleType(attrDef.Datatype.TypeCode);
#endif

                // parse nmtoken list
                if (GetToken(false) != Token.Nmtoken)
                    goto UnexpectedError;
#if !SILVERLIGHT
                attrDef.AddValue(GetNameString());
#endif

                for (;;)
                {
                    switch (GetToken(false))
                    {
                        case Token.Or:
                            if (GetToken(false) != Token.Nmtoken)
                                goto UnexpectedError;
                            string nmtoken = GetNmtokenString();
#if !SILVERLIGHT
                            if (_validate && !_v1Compat && attrDef.Values != null && attrDef.Values.Contains(nmtoken) && !ignoreErrors)
                            {
                                SendValidationEvent(XmlSeverityType.Error, new XmlSchemaException(SR.Xml_AttlistDuplEnumValue, nmtoken, BaseUriStr, (int)LineNo, (int)LinePos));
                            }
                            attrDef.AddValue(nmtoken);
#endif
                            break;
                        case Token.RightParen:
                            return;
                        default:
                            goto UnexpectedError;
                    }
                }
            }
            else
            {
                goto UnexpectedError;
            }

        UnexpectedError:
            OnUnexpectedError();
        }
        private void ParseAttlistType( SchemaAttDef attrDef, SchemaElementDecl elementDecl ) {
            Token token = GetToken( true );

            if ( token != Token.CDATA ) {
                elementDecl.HasNonCDataAttribute = true;
            }
            
            if ( IsAttributeValueType( token ) ) {
                attrDef.Datatype = XmlSchemaDatatype.FromXmlTokenizedType( (XmlTokenizedType)(int)token );
                attrDef.SchemaType = XmlSchemaType.GetBuiltInSimpleType( attrDef.Datatype.TypeCode );

                switch ( token ) {
                    case Token.NOTATION:
                        break;
                    case Token.ID:
                        if ( validate && elementDecl.IsIdDeclared ) {
                            SchemaAttDef idAttrDef = elementDecl.GetAttDef( attrDef.Name );
                            if ( idAttrDef == null || idAttrDef.Datatype.TokenizedType != XmlTokenizedType.ID ) {
                                SendValidationEvent( XmlSeverityType.Error, Res.Sch_IdAttrDeclared, elementDecl.Name.ToString() );
                            }
                        }
                        elementDecl.IsIdDeclared = true;
                        return;
                    default:
                        return;
                }
                // check notation constrains
                if ( validate ) {
                    if ( elementDecl.IsNotationDeclared ) {
                        SendValidationEvent( curPos - 8, XmlSeverityType.Error, Res.Sch_DupNotationAttribute, elementDecl.Name.ToString() ); // 8 == strlen("NOTATION")
                    }
                    else {
                        if ( elementDecl.ContentValidator != null && 
                            elementDecl.ContentValidator.ContentType == XmlSchemaContentType.Empty ) {
                            SendValidationEvent( curPos - 8, XmlSeverityType.Error, Res.Sch_NotationAttributeOnEmptyElement, elementDecl.Name.ToString() );// 8 == strlen("NOTATION")
                        }
                        elementDecl.IsNotationDeclared = true;
                    }
                }

                if ( GetToken( true ) != Token.LeftParen ) {
                    goto UnexpectedError;
                }

                // parse notation list
                if ( GetToken( false ) != Token.Name ) {
                    goto UnexpectedError;
                }
                for (;;) {
                    string notationName = GetNameString();
                    if ( schemaInfo.Notations[notationName] == null ) {
                        if ( undeclaredNotations == null ) {
                            undeclaredNotations = new Hashtable();
                        }
                        UndeclaredNotation un = new UndeclaredNotation( notationName, LineNo, LinePos - notationName.Length );
                        UndeclaredNotation loggedUn = (UndeclaredNotation)undeclaredNotations[notationName];
                        if ( loggedUn != null ) {
                            un.next = loggedUn.next;
                            loggedUn.next = un;
                        }
                        else {
                            undeclaredNotations.Add( notationName, un );
                        }
                    }
                    if ( validate && !v1Compat && attrDef.Values != null && attrDef.Values.Contains( notationName ) ) {
                        SendValidationEvent( XmlSeverityType.Error, new XmlSchemaException( Res.Xml_AttlistDuplNotationValue, notationName, BaseUriStr, (int)LineNo, (int)LinePos ) );
                    }
                    attrDef.AddValue( notationName );

                    switch ( GetToken( false ) ) {
                        case Token.Or:
                            if ( GetToken( false ) != Token.Name ) {
                                goto UnexpectedError;
                            }
                            continue;
                        case Token.RightParen:
                            return;
                        default:
                            goto UnexpectedError;
                    }
                }
            }
            else if ( token == Token.LeftParen ) {
                attrDef.Datatype = XmlSchemaDatatype.FromXmlTokenizedType( XmlTokenizedType.ENUMERATION );
                attrDef.SchemaType = XmlSchemaType.GetBuiltInSimpleType( attrDef.Datatype.TypeCode );

                // parse nmtoken list
                if ( GetToken( false ) != Token.Nmtoken ) 
                    goto UnexpectedError;
                attrDef.AddValue( GetNameString() );

                for (;;) {
                    switch ( GetToken( false ) ) {
                        case Token.Or:
                            if ( GetToken( false ) != Token.Nmtoken ) 
                                goto UnexpectedError;
                            string nmtoken = GetNmtokenString();
                            if ( validate && !v1Compat && attrDef.Values != null && attrDef.Values.Contains( nmtoken ) ) {
                                SendValidationEvent( XmlSeverityType.Error, new XmlSchemaException( Res.Xml_AttlistDuplEnumValue, nmtoken, BaseUriStr, (int)LineNo, (int)LinePos ) );
                            }
                            attrDef.AddValue( nmtoken );
                            break;
                        case Token.RightParen:
                            return;
                        default:
                            goto UnexpectedError;
                    }
                }
            }
            else {
                goto UnexpectedError;
            }

        UnexpectedError:
            OnUnexpectedError();
        }
        internal SchemaAttDef GetAttributeXsd(SchemaElementDecl ed, XmlQualifiedName qname, XmlSchemaObject partialValidationType, out AttributeMatchState attributeMatchState)
        {
            SchemaAttDef attdef = null;

            attributeMatchState = AttributeMatchState.UndeclaredAttribute;
            if (ed != null)
            {
                attdef = ed.GetAttDef(qname);
                if (attdef != null)
                {
                    attributeMatchState = AttributeMatchState.AttributeFound;
                    return(attdef);
                }
                XmlSchemaAnyAttribute any = ed.AnyAttribute;
                if (any != null)
                {
                    if (!any.NamespaceList.Allows(qname))
                    {
                        attributeMatchState = AttributeMatchState.ProhibitedAnyAttribute;
                    }
                    else if (any.ProcessContentsCorrect != XmlSchemaContentProcessing.Skip)
                    {
                        if (attributeDecls.TryGetValue(qname, out attdef))
                        {
                            if (attdef.Datatype.TypeCode == XmlTypeCode.Id)   //anyAttribute match whose type is ID
                            {
                                attributeMatchState = AttributeMatchState.AnyIdAttributeFound;
                            }
                            else
                            {
                                attributeMatchState = AttributeMatchState.AttributeFound;
                            }
                        }
                        else if (any.ProcessContentsCorrect == XmlSchemaContentProcessing.Lax)
                        {
                            attributeMatchState = AttributeMatchState.AnyAttributeLax;
                        }
                    }
                    else
                    {
                        attributeMatchState = AttributeMatchState.AnyAttributeSkip;
                    }
                }
                else if (ed.ProhibitedAttributes.ContainsKey(qname))
                {
                    attributeMatchState = AttributeMatchState.ProhibitedAttribute;
                }
            }
            else if (partialValidationType != null)
            {
                XmlSchemaAttribute attr = partialValidationType as XmlSchemaAttribute;
                if (attr != null)
                {
                    if (qname.Equals(attr.QualifiedName))
                    {
                        attdef = attr.AttDef;
                        attributeMatchState = AttributeMatchState.AttributeFound;
                    }
                    else
                    {
                        attributeMatchState = AttributeMatchState.AttributeNameMismatch;
                    }
                }
                else
                {
                    attributeMatchState = AttributeMatchState.ValidateAttributeInvalidCall;
                }
            }
            else
            {
                if (attributeDecls.TryGetValue(qname, out attdef))
                {
                    attributeMatchState = AttributeMatchState.AttributeFound;
                }
                else
                {
                    attributeMatchState = AttributeMatchState.UndeclaredElementAndAttribute;
                }
            }
            return(attdef);
        }
        internal SchemaAttDef GetAttribute(SchemaElementDecl ed, XmlQualifiedName qname, ref bool skip)
        {
            SchemaAttDef attdef = null;

            if (ed != null)   // local attribute or XSD
            {
                skip   = false;
                attdef = ed.GetAttDef(qname);
                if (attdef == null)
                {
                    // In DTD, every attribute must be declared.
                    if (schemaType == SchemaType.DTD)
                    {
                        throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, qname.ToString());
                    }
                    else if (schemaType == SchemaType.XDR)
                    {
                        if (ed.Content.IsOpen)
                        {
                            attdef = (SchemaAttDef)attributeDecls[qname];
                            if ((attdef == null) && ((qname.Namespace == String.Empty) || HasSchema(qname.Namespace)))
                            {
                                throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, qname.ToString());
                            }
                        }
                        else
                        {
                            throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, qname.ToString());
                        }
                    }
                    else   //XML Schema
                    {
                        XmlSchemaAnyAttribute any = ed.AnyAttribute;
                        if (any != null)
                        {
                            if (any.NamespaceList.Allows(qname))
                            {
                                if (any.ProcessContentsCorrect != XmlSchemaContentProcessing.Skip)
                                {
                                    attdef = (SchemaAttDef)attributeDecls[qname];
                                    if (attdef == null && any.ProcessContentsCorrect == XmlSchemaContentProcessing.Strict)
                                    {
                                        throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, qname.ToString());
                                    }
                                }
                                else
                                {
                                    skip = true;
                                }
                            }
                            else
                            {
                                throw new XmlSchemaException(Res.Sch_ProhibitedAttribute, qname.ToString());
                            }
                        }
                        else if (ed.ProhibitedAttributes[qname] != null)
                        {
                            throw new XmlSchemaException(Res.Sch_ProhibitedAttribute, qname.ToString());
                        }
                        else
                        {
                            throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, qname.ToString());
                        }
                    }
                }
            }
            else   // global attribute
            {
                if (!skip)
                {
                    attdef = (SchemaAttDef)attributeDecls[qname];
                    if ((attdef == null) && HasSchema(qname.Namespace))
                    {
                        throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, qname.ToString());
                    }
                }
            }
            return(attdef);
        }
 internal SchemaAttDef GetAttributeXsd(SchemaElementDecl ed, XmlQualifiedName qname, XmlSchemaObject partialValidationType, out AttributeMatchState attributeMatchState) {
     SchemaAttDef attdef = null;
     attributeMatchState = AttributeMatchState.UndeclaredAttribute;
     if (ed != null) {
         attdef = ed.GetAttDef(qname);
         if (attdef != null) {
             attributeMatchState = AttributeMatchState.AttributeFound;
             return attdef;
         }
         XmlSchemaAnyAttribute any = ed.AnyAttribute;
         if (any != null) {
             if (!any.NamespaceList.Allows(qname)) {
                 attributeMatchState = AttributeMatchState.ProhibitedAnyAttribute;
             }
             else if (any.ProcessContentsCorrect != XmlSchemaContentProcessing.Skip) {
                 if (attributeDecls.TryGetValue(qname, out attdef)) {
                     if (attdef.Datatype.TypeCode == XmlTypeCode.Id) { //anyAttribute match whose type is ID
                         attributeMatchState = AttributeMatchState.AnyIdAttributeFound;
                     }
                     else {
                         attributeMatchState = AttributeMatchState.AttributeFound;
                     }
                 }
                 else if (any.ProcessContentsCorrect == XmlSchemaContentProcessing.Lax) {
                     attributeMatchState = AttributeMatchState.AnyAttributeLax;
                 }
             }
             else {
                 attributeMatchState = AttributeMatchState.AnyAttributeSkip;
             }
         }
         else if (ed.ProhibitedAttributes.ContainsKey(qname)) {
             attributeMatchState = AttributeMatchState.ProhibitedAttribute;
         }
     }
     else if (partialValidationType != null) {
         XmlSchemaAttribute attr = partialValidationType as XmlSchemaAttribute;
         if (attr != null) {
             if (qname.Equals(attr.QualifiedName)) {
                 attdef = attr.AttDef;
                 attributeMatchState = AttributeMatchState.AttributeFound;
             }
             else {
                 attributeMatchState = AttributeMatchState.AttributeNameMismatch;
             }
         }
         else {
             attributeMatchState = AttributeMatchState.ValidateAttributeInvalidCall;
         }
     }
     else {
         if (attributeDecls.TryGetValue(qname, out attdef)) {
             attributeMatchState = AttributeMatchState.AttributeFound;
         }
         else {
             attributeMatchState = AttributeMatchState.UndeclaredElementAndAttribute;
         }
     }
     return attdef;
 }
 internal SchemaAttDef GetAttributeXdr(SchemaElementDecl ed, XmlQualifiedName qname) {
     SchemaAttDef attdef = null;
     if (ed != null) {
         attdef = ed.GetAttDef(qname);;
         if (attdef == null) {
             if (!ed.ContentValidator.IsOpen || qname.Namespace.Length == 0) {
                 throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, qname.ToString());
             }
             if (!attributeDecls.TryGetValue(qname, out attdef) && targetNamespaces.ContainsKey(qname.Namespace)) {
                 throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, qname.ToString());
             }
         }
     }
     return attdef;
 }
Exemple #8
0
 internal SchemaAttDef GetAttribute(SchemaElementDecl ed, XmlQualifiedName qname, out bool skip) {
     SchemaAttDef attdef = null;
     skip = false;
     if (ed != null) { // local attribute or XSD
         attdef = ed.GetAttDef(qname);
         if (attdef == null) {
             // In DTD, every attribute must be declared.
             if (schemaType == SchemaType.DTD) {
                 throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, qname.ToString());
             }
             else if (schemaType == SchemaType.XDR) {
                 if (ed.Content.IsOpen) {
                     attdef = (SchemaAttDef)attributeDecls[qname];
                     if ((attdef == null) && ((qname.Namespace == String.Empty) || HasSchema(qname.Namespace))) {
                         throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, qname.ToString());
                     }
                 }
                 else {
                     throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, qname.ToString());
                 }
             }
             else { //XML Schema
                 XmlSchemaAnyAttribute any = ed.AnyAttribute;
                 if (any != null) {
                     if (any.NamespaceList.Allows(qname) && ed.ProhibitedAttributes[qname] == null) {
                         if (any.ProcessContentsCorrect != XmlSchemaContentProcessing.Skip) {
                             attdef = (SchemaAttDef)attributeDecls[qname];
                             if (attdef == null && any.ProcessContentsCorrect == XmlSchemaContentProcessing.Strict) {
                                 throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, qname.ToString());
                             }
                         }
                         else {
                             skip = true;
                         }
                     }
                     else {
                         throw new XmlSchemaException(Res.Sch_ProhibitedAttribute, qname.ToString());
                     }
                 }
                 else if (ed.ProhibitedAttributes[qname] != null) {
                     throw new XmlSchemaException(Res.Sch_ProhibitedAttribute, qname.ToString());
                 }
                 else {
                     throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, qname.ToString());
                 }
             }
         }
     }
     else { // global attribute
         attdef = (SchemaAttDef)attributeDecls[qname];
         if ((attdef == null) && HasSchema(qname.Namespace)) {
             throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, qname.ToString());
         }
     }
     return attdef;
 }