token.setType(Type.ATTRIBUTE);
parseName("attribute");
if (pos == token.getStartOffset())
throw new XMLParseException("Expected attribute name", source, pos);
skipWhiteSpace();
expect('=');
skipWhiteSpace();
char c = 0;
if (pos < source.length())
c = source.charAt(pos);
if (c != '\'' && c != '"')
throw new XMLParseException("Expected single or double quotes", source, pos);
char endChar = c;
boolean insideEntity = false;
int errorPos = pos;
while (true) {
pos++;
if (pos >= source.length()) {
int i = Math.min(20, source.length() - token.getStartOffset());
throw new XMLParseException("Missing end quote (" + endChar + ") of attribute: "
+ lookAheadForErrorMessage(null, token.getStartOffset(), i), token);
}
c = source.charAt(pos);
if (c == endChar)
break;
if (c == '<')
throw new XMLParseException("Illegal character in attribute value: '" + c + "'", source, pos);
if (c == '&') {
insideEntity = true;
errorPos = pos;
} else if (c == ';') {
verifyEntity(errorPos, pos + 1);
insideEntity = false;
} else {
String msg = charValidator.isValid(source, pos);
if (msg != null)
throw new XMLParseException("Illegal character found in attribute value. " + msg, source, pos);
skipChar(c);
pos--;
}
}
if (insideEntity) {
throw new XMLParseException("Missing ';' after '&': " + lookAheadForErrorMessage(null, errorPos, 20), source, errorPos);
}
// Skip end-char
pos++;
}