internal bool AddDefaultAttribute( SchemaAttDef attrDef, bool definedInDtd ) { string localName = attrDef.Name.Name; string prefix = attrDef.Prefix; string ns = attrDef.Name.Namespace; // DTD default attribute if ( definedInDtd ) { if ( prefix.Length > 0 ) { attrNeedNamespaceLookup = true; } } // XSD/XDR default attribute else { // atomize namesspace - Xsd Validator does not need to have the same nametable ns = nameTable.Add( ns ); if ( prefix.Length == 0 && ns.Length > 0 ) { prefix = namespaceManager.LookupPrefix( ns ); Debug.Assert( prefix != null ); if ( prefix == null ) { prefix = string.Empty; } } } // atomize names - Xsd Validator does not need to have the same nametable localName = nameTable.Add( localName ); prefix = nameTable.Add( prefix ); // check for duplicates 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; } } // check the default attribute value if it has a valid value according to its type if ( definedInDtd && DtdValidation && !attrDef.DefaultValueChecked ) { attrDef.CheckDefaultValue( dtdParserProxy.DtdSchemaInfo, dtdParserProxy ); } // setup the attribute NodeData attr = AddAttribute( localName, prefix, prefix.Length > 0 ? null : localName ); if ( !definedInDtd ) { Debug.Assert( ns != null ); attr.ns = ns; } attr.SetValue( attrDef.DefaultValueExpanded ); attr.IsDefaultAttribute = true; attr.schemaType = ( attrDef.SchemaType == null ) ? (object)attrDef.Datatype : (object)attrDef.SchemaType; attr.typedValue = attrDef.DefaultValueTyped; attr.lineInfo.Set( attrDef.LineNum, attrDef.LinePos ); attr.lineInfo2.Set( attrDef.ValueLineNum, attrDef.ValueLinePos ); // handle special attributes: if ( attr.prefix.Length == 0 ) { // default namespace declaration if ( Ref.Equal( attr.localName, XmlNs ) ) { OnDefaultNamespaceDecl( attr ); if ( !definedInDtd ) { // change element default namespace Debug.Assert( nodes[index].type == XmlNodeType.Element ); if ( nodes[index].prefix.Length == 0 ) { nodes[index].ns = xmlContext.defaultNamespace; } } } } else { // prefixed namespace declaration if ( Ref.Equal( attr.prefix, XmlNs ) ) { OnNamespaceDecl( attr ); if ( !definedInDtd ) { // change namespace of current element and attributes string pref = attr.localName; Debug.Assert( nodes[index].type == XmlNodeType.Element ); for ( int i = index; i < index + attrCount + 1; i++ ) { if ( nodes[i].prefix.Equals( pref ) ) { nodes[i].ns = namespaceManager.LookupNamespace( pref ); } } } } // xml: attribute else { if ( attrDef.Reserved != SchemaAttDef.Reserve.None ) { OnXmlReservedAttribute( attr ); } } } fullAttrCleanup = true; return true; }