* @throws OMException
*/
public int next() throws OMException {
try {
if (done) {
throw new OMException();
}
int token = getNextElementToParse();
if (!cache) {
return token;
}
switch (token) {
case XMLStreamConstants.START_ELEMENT:
lastNode = createOMElement();
break;
case XMLStreamConstants.START_DOCUMENT:
document.setXMLVersion(
parser.getVersion() != null ?
parser.getVersion() : "1.0");
document.setCharsetEncoding(
parser.getEncoding() != null ?
parser.getEncoding() : "utf-8");
document.setStandalone(
parser.isStandalone() ? YES : NO);
break;
case XMLStreamConstants.CHARACTERS:
lastNode = applyTextFilter(XMLStreamConstants.CHARACTERS);
break;
case XMLStreamConstants.CDATA:
lastNode = applyTextFilter(XMLStreamConstants.CDATA);
break;
case XMLStreamConstants.END_ELEMENT:
endElement();
break;
case XMLStreamConstants.END_DOCUMENT:
done = true;
((OMContainerEx) this.document).setComplete(true);
break;
case XMLStreamConstants.SPACE:
if (!ignoreWhitespace)
lastNode = createOMText(XMLStreamConstants.SPACE);
break;
case XMLStreamConstants.COMMENT:
if (!ignoreComments) createComment();
break;
case XMLStreamConstants.DTD:
// Current StAX cursor model implementations inconsistently handle DTDs.
// Woodstox, for instance, does not provide a means of getting to the complete
// doctype declaration (which is actually valid according to the spec, which
// is broken). The StAX reference impl returns the complete doctype declaration
// despite the fact that doing so is apparently against the spec. We can get
// to the complete declaration in Woodstox if we want to use their proprietary
// extension APIs. It's unclear how other Stax impls handle this. So.. for now,
// we're just going to ignore the DTD. The DTD will still be processed as far
// as entities are concerned, but we will not be able to reserialize the parsed
// document with the DTD. Since very few folks actually use DTD's in feeds
// right now (and we should likely be encouraging folks not to do so), this
// shouldn't be that big of a problem
// if (!parserOptions.getIgnoreDoctype())
// createDTD();
break;
case XMLStreamConstants.PROCESSING_INSTRUCTION:
if (!ignorePI) createPI();
break;
case XMLStreamConstants.ENTITY_REFERENCE:
lastNode = createOMText(XMLStreamConstants.ENTITY_REFERENCE);
break;
default :
throw new OMException();
}
return token;
} catch (OMException e) {
throw e;
} catch (Exception e) {
throw new OMException(e);
}
}