if (START_DOCUMENT != state) {
throw new JDOMException("JDOM requires that XMLStreamReaders " +
"are at their beginning when being processed.");
}
final Document document = factory.document(null);
while (state != END_DOCUMENT) {
switch (state) {
case START_DOCUMENT:
// for the <?xml version="..." standalone=".."?>
document.setBaseURI(stream.getLocation().getSystemId());
document.setProperty("ENCODING_SCHEME",
stream.getCharacterEncodingScheme());
document.setProperty("STANDALONE",
String.valueOf(stream.isStandalone()));
document.setProperty("ENCODING",
stream.getEncoding());
break;
case DTD:
document.setDocType(DTDParser.parse(
stream.getText(), factory));
break;
case START_ELEMENT:
document.setRootElement(processElementFragment(factory, stream));
break;
case END_ELEMENT:
throw new JDOMException("Unexpected XMLStream event at Document level: END_ELEMENT");
case ENTITY_REFERENCE:
throw new JDOMException("Unexpected XMLStream event at Document level: ENTITY_REFERENCE");
case CDATA:
throw new JDOMException("Unexpected XMLStream event at Document level: CDATA");
case SPACE:
throw new JDOMException("Unexpected XMLStream event at Document level: SPACE");
case CHARACTERS:
throw new JDOMException("Unexpected XMLStream event at Document level: CHARACTERS");
case COMMENT:
document.addContent(
factory.comment(stream.getText()));
break;
case PROCESSING_INSTRUCTION:
document.addContent(factory.processingInstruction(
stream.getPITarget(), stream.getPIData()));
break;
default:
throw new JDOMException("Unexpected XMLStream event " + state);