if((versionEnd - versionStart != 3)
|| buf[versionStart] != '1'
|| buf[versionStart+1] != '.'
|| buf[versionStart+2] != '0')
{
throw new XMLStreamException(
"only 1.0 is supported as <?xml version not '"
+printable(new String(buf, versionStart, versionEnd))+"'", getLocation());
}
xmlVersion = new String(buf, versionStart, versionEnd-versionStart);
// [80] EncodingDecl ::= S 'encoding' Eq ('"' EncName '"' | "'" EncName "'" )
char ch = more();
ch = skipS(ch);
if(ch != '?') {
ch = skipS(ch);
if(ch == ENCODING[0]) {
ch = requireInput(ch, ENCODING);
ch = skipS(ch);
if(ch != '=') {
throw new XMLStreamException(
"expected equals sign (=) after encoding and not "+printable(ch), getLocation());
}
ch = more();
ch = skipS(ch);
if(ch != '\'' && ch != '"') {
throw new XMLStreamException(
"expected apostrophe (') or quotation mark (\") after encoding and not "
+printable(ch), getLocation());
}
char quotChar = ch;
int encodingStart = pos;
ch = more();
// [81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*
if((ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z'))
{
throw new XMLStreamException(
"<?xml encoding name expected to start with [A-Za-z]"
+" not "+printable(ch), getLocation());
}
ch = more();
while(ch != quotChar) {
if((ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z') && (ch < '0' || ch > '9')
&& ch != '.' && ch != '_' && ch != '-')
{
throw new XMLStreamException(
"<?xml encoding value expected to be in ([A-Za-z0-9._] | '-')"
+" not "+printable(ch), getLocation());
}
ch = more();
}
int encodingEnd = pos - 1;
//String encodingName = newStringIntern(buf, encodingStart, encodingEnd);
// TODO reconcile with setInput encodingName
charEncodingScheme = newString(buf, encodingStart, encodingEnd-encodingStart);
ch = more();
ch = skipS(ch);
}
// [32] SDDecl ::= S 'standalone' Eq (("'" ('yes' | 'no') "'") | ('"' ('yes' | 'no') '"'))
if(ch != '?') {
ch = skipS(ch);
ch = requireInput(ch, STANDALONE);
ch = skipS(ch);
if(ch != '=') {
throw new XMLStreamException(
"expected equals sign (=) after standalone and not "+printable(ch),
getLocation());
}
ch = more();
ch = skipS(ch);
if(ch != '\'' && ch != '"') {
throw new XMLStreamException(
"expected apostrophe (') or quotation mark (\") after encoding and not "
+printable(ch), getLocation());
}
char quotChar = ch;
int standaloneStart = pos;
ch = more();
if(ch == 'y') {
ch = requireInput(ch, YES);
standalone = true;
} else if(ch == 'n') {
ch = requireInput(ch, NO);
standalone = false;
} else {
throw new XMLStreamException(
"expected 'yes' or 'no' after standalone and not "
+printable(ch), getLocation());
}
standaloneSet = true;
if(ch != quotChar) {
throw new XMLStreamException(
"expected "+quotChar+" after standalone value not "
+printable(ch), getLocation());
}
ch = more();
}
}
ch = skipS(ch);
if(ch != '?') {
throw new XMLStreamException(
"expected ?> as last part of <?xml not "
+printable(ch), getLocation());
}
ch = more();
if(ch != '>') {
throw new XMLStreamException(
"expected ?> as last part of <?xml not "
+printable(ch), getLocation());
}
} catch (EOFException eofe) {
throw new XMLStreamException(EOF_MSG, getLocation(), eofe);
}
}