private void SetLiteralValues(XmlAttributeTokenInfo fld) { // // get the literal token // _Scanner.ScanToken(XmlToken.EQUALS); _Scanner.ScanToken(XmlToken.QUOTE); String nameWPrefix = fld.NameWPrefix; int nameLength = nameWPrefix.Length; fld.QuoteChar = _Scanner.QuoteChar(); fld.NsAttribute = false; // // always expand literals and we also need to remember the value offsets // int pos = _Scanner.CurrentPos; int lineNum = _Scanner.LineNum; int linePos = _Scanner.AbsoluteLinePos; if (_Scanner.ScanLiteral()) { _Scanner.CurrentPos = pos; _Scanner.AbsoluteLinePos = linePos; _Scanner.LineNum = lineNum; fld.ValueContainEntity = ValueContainEntity.None; ExpandLiteral(fld); } else { fld.ValueContainEntity = ValueContainEntity.None; fld.SetValue(_Scanner, null, _Scanner.StartPos, _Scanner.TextLength); } // check xmlns, xml:space, xml:lang // if (nameWPrefix[0] != 'x' || nameLength < 5) { goto cleanup; } if (nameWPrefix[1] == 'm' && nameWPrefix[2] == 'l') { if (nameWPrefix[3] == 'n' && nameWPrefix[4] == 's') { fld.NsAttribute = true; fld.FixNSNames(); } else if ((Object)nameWPrefix == (Object)_XmlSpaceAtom) { // // xml:space // String val = fld.GetValue(); _XmlSpace = ConvertXmlSpace(val, fld.LineNum, fld.LinePos ); goto cleanup; } else if ((Object)nameWPrefix == (Object)_XmlLangAtom) { // // xml:lang // _XmlLang = fld.GetValue(); goto cleanup; } } cleanup: return; }
// This method parses the entire attribute value expanding all the entities // it finds into an internal buffer. private void ExpandLiteral(XmlAttributeTokenInfo currToken) { // use our little buffer to build up the expanded attribute value. _StringBuilder.Length = 0; int start = _Scanner.CurrentPos; int token = _Scanner.ScanLiteral(true, false, true, false); char ch; int offset = 0; int length = 0; char[] array = null; bool expanded = false; int depth = 0; while (token != XmlToken.ENDQUOTE) { if (!expanded && length != 0) { // must have more than one text token, so it's time to buffer up. expanded = true; _StringBuilder.Append(array, offset, length); } switch (token) { case XmlToken.TEXT: if (!expanded) { array = _Scanner.InternalBuffer; offset = _Scanner.TextOffset; length = _Scanner.TextLength; } else { _StringBuilder.Append(_Scanner.InternalBuffer, _Scanner.TextOffset, _Scanner.TextLength); } break; case XmlToken.ENTITYREF: expanded = true; ch = _Scanner.ScanNamedEntity(); // // ch == 0 if general entity // ch != 0 if build in entity, for example: < // if (ch == 0) { _StringBuilder.Append(_Scanner.InternalBuffer, _Scanner.TextOffset-1, _Scanner.TextLength+1); currToken.ValueContainEntity = ValueContainEntity.NotResolved; //currToken.UndeclaredEntity = true; break; } else { _StringBuilder.Append(ch); _Scanner.Advance(); // consume the ';' } break; case XmlToken.HEXENTREF: expanded = true; _StringBuilder.Append(_Scanner.ScanHexEntity()); break; case XmlToken.NUMENTREF: expanded = true; _StringBuilder.Append(_Scanner.ScanDecEntity()); break; case XmlToken.EOF: depth--; break; } token = _Scanner.ScanLiteral(true, false, depth==0, false); } String str = _StringBuilder.ToString(); currToken.SetValue(_Scanner, str, start, _Scanner.CurrentPos - start); }