}
// Implements XMLStreamReader Interface.
public CharArray getElementText() throws XMLStreamException {
// Derived from interface specification code.
if (getEventType() != XMLStreamConstants.START_ELEMENT) { throw new XMLStreamException(
"Parser must be on START_ELEMENT to read next text",
getLocation()); }
CharArray text = null;
int eventType = next();
while (eventType != XMLStreamConstants.END_ELEMENT) {
if (eventType == XMLStreamConstants.CHARACTERS) {
if (text == null) {
text = getText();
} else { // Merge (adjacent text, comments and PI are not kept).
text.setArray(_data, text.offset(), text.length()
+ getText().length());
}
} else if (eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
|| eventType == XMLStreamConstants.COMMENT) {
// Skips (not kept).
} else if (eventType == XMLStreamConstants.END_DOCUMENT) {
throw new XMLStreamException(
"Unexpected end of document when reading element text content",
getLocation());
} else if (eventType == XMLStreamConstants.START_ELEMENT) {
throw new XMLStreamException(
"Element text content may not contain START_ELEMENT",
getLocation());
} else {
throw new XMLStreamException("Unexpected event type "
+ NAMES_OF_EVENTS[eventType], getLocation());
}
eventType = next();
}
return (text != null) ? text : newSeq(0, 0);