private string ExpandAttValue(string s, ref bool fEntityRef, int lineNum, int linePos) { if (s.Length == 0) return s; string code = null; string msg = null; char ch; XmlScanner scanner = _Scanner; _StringBuilder.Length = 0; _Scanner = new XmlScanner(s.ToCharArray(), _NameTable, lineNum, linePos); while (true) { _Token = _Scanner.ScanLiteral(true, false, false, false); switch (_Token) { case XmlToken.EOF: PopAttValueScanner(); if (_Scanner == null) { _Scanner = scanner; return _StringBuilder.ToString(); } break; case XmlToken.ENTITYREF: fEntityRef = true; _Scanner.InDTD = false; ch = _Scanner.ScanNamedEntity(); _Scanner.InDTD = true; if (ch == 0) { XmlQualifiedName name = new XmlQualifiedName(_Scanner.GetTextAtom()); _Scanner.Advance(); SchemaEntity en = (SchemaEntity)_SchemaInfo.GeneralEntities[name]; if (en != null) { if (!en.IsExternal) { if (!en.IsProcessed) { if (en.Text != null && en.Text != string.Empty) { PushAttValueScanner(_Scanner, en); _Scanner = new XmlScanner(en.Text.ToCharArray(), _NameTable, en.Line, en.Pos + 1); } } else { // well-formness error, see xml spec [68] code = Res.Xml_RecursiveGenEntity; msg = name.Name; goto error; } } else { // well-formness error, see xml spec [68] code = Res.Xml_ExternalEntityInAttValue; msg = name.Name; goto error; } } else { // well-formness error, see xml spec [68] code = Res.Xml_UndeclaredEntity; msg = name.Name; if(_IsInternal) { goto error; } else { SendValidationEvent(code, msg); } } } else { _Scanner.Advance(); _StringBuilder.Append(ch); } break; case XmlToken.NUMENTREF: fEntityRef = true; _StringBuilder.Append(_Scanner.ScanDecEntity()); break; case XmlToken.HEXENTREF: fEntityRef = true; _StringBuilder.Append(_Scanner.ScanHexEntity()); break; case XmlToken.TEXT: _StringBuilder.Append(_Scanner.GetText()); break; default: code = Res.Xml_UnexpectedToken; goto error; } } error: Debug.Assert(code != null); throw new XmlException(code, msg, _Scanner.StartLineNum , _Scanner.StartLinePos); }