// read element content
while (true) {
if (!eventReader.hasNext()) {
String msg = "Unexpected end of stream while reading"
+ " element content";
throw new XMLStreamException(msg);
}
XMLEvent nextEvent = eventReader.peek();
if (nextEvent.isEndElement()) {
EndElement endElem = eventReader.nextEvent().asEndElement();
if (!endElem.getName().equals(startTag.getName())) {
throw new XMLStreamException("Expected "
+ startTag.getName() + " end-tag, but found"
+ endElem.getName());
}
break;
}
Node child = readNode(eventReader);
elem.add(child);
}
return elem;
} else {
throw new XMLStreamException("Expected Element event, found: "
+ event);
}
}