private void AddUndeclaredNotation(string notationName) { if (_undeclaredNotations == null) { _undeclaredNotations = new Dictionary<string, UndeclaredNotation>(); } UndeclaredNotation un = new UndeclaredNotation(notationName, LineNo, LinePos - notationName.Length); UndeclaredNotation loggedUn; if (_undeclaredNotations.TryGetValue(notationName, out loggedUn)) { un.next = loggedUn.next; loggedUn.next = un; } else { _undeclaredNotations.Add(notationName, un); } }
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 UndeclaredNotation(string name, int lineNo, int linePos) { this.name = name; this.lineNo = lineNo; this.linePos = linePos; this.next = null; }
private void ParseEntityDecl() { bool isParamEntity = false; SchemaEntity entity = null; // get entity name and type switch ( GetToken( true ) ) { case Token.Percent: isParamEntity = true; if ( GetToken( true ) != Token.Name ) { goto UnexpectedError; } goto case Token.Name; case Token.Name: // create entity object XmlQualifiedName entityName = GetNameQualified( false ); entity = new SchemaEntity( entityName, isParamEntity ); entity.BaseURI = BaseUriStr; entity.DeclaredURI = ( externalDtdBaseUri.Length == 0 ) ? documentBaseUri : externalDtdBaseUri; if ( isParamEntity ) { if ( schemaInfo.ParameterEntities[ entityName ] == null ) { schemaInfo.ParameterEntities.Add( entityName, entity ); } } else { if ( schemaInfo.GeneralEntities[ entityName ] == null ) { schemaInfo.GeneralEntities.Add( entityName, entity ); } } entity.DeclaredInExternal = !ParsingInternalSubset; entity.IsProcessed = true; break; default: goto UnexpectedError; } Token token = GetToken( true ); switch ( token ) { case Token.PUBLIC: case Token.SYSTEM: string systemId; string publicId; ParseExternalId( token, Token.EntityDecl, out publicId, out systemId ); entity.IsExternal = true; entity.Url = systemId; entity.Pubid = publicId; if ( GetToken( false ) == Token.NData ) { if ( isParamEntity ) { ThrowUnexpectedToken( curPos - 5, ">" ); // 5 == strlen("NDATA") } if ( !whitespaceSeen ) { Throw( curPos - 5, Res.Xml_ExpectingWhiteSpace, "NDATA" ); } if ( GetToken( true ) != Token.Name ) { goto UnexpectedError; } entity.NData = GetNameQualified( false ); string notationName = entity.NData.Name; 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 ); } } } break; case Token.Literal: entity.Text = GetValue(); entity.Line = (int)literalLineInfo.lineNo; entity.Pos = (int)literalLineInfo.linePos; break; default: goto UnexpectedError; } if ( GetToken( false ) == Token.GreaterThan ) { entity.IsProcessed = false; return; } UnexpectedError: OnUnexpectedError(); }