in src/org/apache/xerces/impl/XML11NSDocumentScannerImpl.java [340:529]
protected boolean scanStartElementAfterName()
throws IOException, XNIException {
// REVISIT - [Q] Why do we need this local variable? -- mrglavas
String rawname = fElementQName.rawname;
if (fBindNamespaces) {
fNamespaceContext.pushContext();
if (fScannerState == SCANNER_STATE_ROOT_ELEMENT) {
if (fPerformValidation) {
fErrorReporter.reportError(
XMLMessageFormatter.XML_DOMAIN,
"MSG_GRAMMAR_NOT_FOUND",
new Object[] { rawname },
XMLErrorReporter.SEVERITY_ERROR);
if (fDoctypeName == null
|| !fDoctypeName.equals(rawname)) {
fErrorReporter.reportError(
XMLMessageFormatter.XML_DOMAIN,
"RootElementTypeMustMatchDoctypedecl",
new Object[] { fDoctypeName, rawname },
XMLErrorReporter.SEVERITY_ERROR);
}
}
}
}
// push element stack
fCurrentElement = fElementStack.pushElement(fElementQName);
// attributes
boolean empty = false;
fAttributes.removeAllAttributes();
do {
// end tag?
int c = fEntityScanner.peekChar();
if (c == '>') {
fEntityScanner.scanChar();
break;
} else if (c == '/') {
fEntityScanner.scanChar();
if (!fEntityScanner.skipChar('>')) {
reportFatalError(
"ElementUnterminated",
new Object[] { rawname });
}
empty = true;
break;
} else if (!isValidNameStartChar(c) || !fSawSpace) {
// Second chance. Check if this character is a high
// surrogate of a valid name start character.
if (!isValidNameStartHighSurrogate(c) || !fSawSpace) {
reportFatalError(
"ElementUnterminated",
new Object[] { rawname });
}
}
// attributes
scanAttribute(fAttributes);
// spaces
fSawSpace = fEntityScanner.skipSpaces();
} while (true);
if (fBindNamespaces) {
// REVISIT: is it required? forbit xmlns prefix for element
if (fElementQName.prefix == XMLSymbols.PREFIX_XMLNS) {
fErrorReporter.reportError(
XMLMessageFormatter.XMLNS_DOMAIN,
"ElementXMLNSPrefix",
new Object[] { fElementQName.rawname },
XMLErrorReporter.SEVERITY_FATAL_ERROR);
}
// bind the element
String prefix =
fElementQName.prefix != null
? fElementQName.prefix
: XMLSymbols.EMPTY_STRING;
// assign uri to the element
fElementQName.uri = fNamespaceContext.getURI(prefix);
// make sure that object in the element stack is updated as well
fCurrentElement.uri = fElementQName.uri;
if (fElementQName.prefix == null && fElementQName.uri != null) {
fElementQName.prefix = XMLSymbols.EMPTY_STRING;
// making sure that the object in the element stack is updated too.
fCurrentElement.prefix = XMLSymbols.EMPTY_STRING;
}
if (fElementQName.prefix != null && fElementQName.uri == null) {
fErrorReporter.reportError(
XMLMessageFormatter.XMLNS_DOMAIN,
"ElementPrefixUnbound",
new Object[] {
fElementQName.prefix,
fElementQName.rawname },
XMLErrorReporter.SEVERITY_FATAL_ERROR);
}
// bind attributes (xmlns are already bound bellow)
int length = fAttributes.getLength();
for (int i = 0; i < length; i++) {
fAttributes.getName(i, fAttributeQName);
String aprefix =
fAttributeQName.prefix != null
? fAttributeQName.prefix
: XMLSymbols.EMPTY_STRING;
String uri = fNamespaceContext.getURI(aprefix);
// REVISIT: try removing the first "if" and see if it is faster.
//
if (fAttributeQName.uri != null
&& fAttributeQName.uri == uri) {
continue;
}
if (aprefix != XMLSymbols.EMPTY_STRING) {
fAttributeQName.uri = uri;
if (uri == null) {
fErrorReporter.reportError(
XMLMessageFormatter.XMLNS_DOMAIN,
"AttributePrefixUnbound",
new Object[] {
fElementQName.rawname,
fAttributeQName.rawname,
aprefix },
XMLErrorReporter.SEVERITY_FATAL_ERROR);
}
fAttributes.setURI(i, uri);
}
}
if (length > 1) {
QName name = fAttributes.checkDuplicatesNS();
if (name != null) {
if (name.uri != null) {
fErrorReporter.reportError(
XMLMessageFormatter.XMLNS_DOMAIN,
"AttributeNSNotUnique",
new Object[] {
fElementQName.rawname,
name.localpart,
name.uri },
XMLErrorReporter.SEVERITY_FATAL_ERROR);
} else {
fErrorReporter.reportError(
XMLMessageFormatter.XMLNS_DOMAIN,
"AttributeNotUnique",
new Object[] {
fElementQName.rawname,
name.rawname },
XMLErrorReporter.SEVERITY_FATAL_ERROR);
}
}
}
}
// call handler
if (fDocumentHandler != null) {
if (empty) {
//decrease the markup depth..
fMarkupDepth--;
// check that this element was opened in the same entity
if (fMarkupDepth < fEntityStack[fEntityDepth - 1]) {
reportFatalError(
"ElementEntityMismatch",
new Object[] { fCurrentElement.rawname });
}
fDocumentHandler.emptyElement(fElementQName, fAttributes, null);
if (fBindNamespaces) {
fNamespaceContext.popContext();
}
//pop the element off the stack..
fElementStack.popElement(fElementQName);
} else {
fDocumentHandler.startElement(fElementQName, fAttributes, null);
}
}
if (DEBUG_CONTENT_SCANNING)
System.out.println("<<< scanStartElementAfterName(): " + empty);
return empty;
} // scanStartElementAfterName()