System.Xml.XmlTextReaderImpl.AddDefaultAttributesAndNormalize C# (CSharp) Method

AddDefaultAttributesAndNormalize() private method

private AddDefaultAttributesAndNormalize ( ) : void
return void
        private void AddDefaultAttributesAndNormalize()
        {
            Debug.Assert(_curNode.type == XmlNodeType.Element);

            IDtdAttributeListInfo attlistInfo = _dtdInfo.LookupAttributeList(_curNode.localName, _curNode.prefix);
            if (attlistInfo == null)
            {
                return;
            }

            // fix non-CDATA attribute value
            if (_normalize && attlistInfo.HasNonCDataAttributes)
            {
                // go through the attributes and normalize it if not CDATA type
                for (int i = _index + 1; i < _index + 1 + _attrCount; i++)
                {
                    NodeData attr = _nodes[i];

                    IDtdAttributeInfo attributeInfo = attlistInfo.LookupAttribute(attr.prefix, attr.localName);
                    if (attributeInfo != null && attributeInfo.IsNonCDataType)
                    {
                        if (DtdValidation && _standalone && attributeInfo.IsDeclaredInExternal)
                        {
                            // VC constraint:
                            // The standalone document declaration must have the value "no" if any external markup declarations
                            // contain declarations of attributes with values subject to normalization, where the attribute appears in
                            // the document with a value which will change as a result of normalization,
                            string oldValue = attr.StringValue;
                            attr.TrimSpacesInValue();

                            if (oldValue != attr.StringValue)
                            {
                                SendValidationEvent(XmlSeverityType.Error, SR.Sch_StandAloneNormalization, attr.GetNameWPrefix(_nameTable), attr.LineNo, attr.LinePos);
                            }
                        }
                        else
                            attr.TrimSpacesInValue();
                    }
                }
            }

            // add default attributes
            IEnumerable<IDtdDefaultAttributeInfo> defaultAttributes = attlistInfo.LookupDefaultAttributes();
            if (defaultAttributes != null)
            {
                int originalAttrCount = _attrCount;
                NodeData[] nameSortedAttributes = null;

                if (_attrCount >= MaxAttrDuplWalkCount)
                {
                    nameSortedAttributes = new NodeData[_attrCount];
                    Array.Copy(_nodes, _index + 1, nameSortedAttributes, 0, _attrCount);
                    Array.Sort<object>(nameSortedAttributes, DtdDefaultAttributeInfoToNodeDataComparer.Instance);
                }

                foreach (IDtdDefaultAttributeInfo defaultAttributeInfo in defaultAttributes)
                {
                    if (AddDefaultAttributeDtd(defaultAttributeInfo, true, nameSortedAttributes))
                    {
                        if (DtdValidation && _standalone && defaultAttributeInfo.IsDeclaredInExternal)
                        {
                            string prefix = defaultAttributeInfo.Prefix;
                            string qname = (prefix.Length == 0) ? defaultAttributeInfo.LocalName : (prefix + ':' + defaultAttributeInfo.LocalName);
                            SendValidationEvent(XmlSeverityType.Error, SR.Sch_UnSpecifiedDefaultAttributeInExternalStandalone, qname, _curNode.LineNo, _curNode.LinePos);
                        }
                    }
                }

                if (originalAttrCount == 0 && _attrNeedNamespaceLookup)
                {
                    AttributeNamespaceLookup();
                    _attrNeedNamespaceLookup = false;
                }
            }
        }
XmlTextReaderImpl