I have the following element declaration:
<xs:element name="period" type="xs:unsignedInt" default="20"/>
I use it as follows:
<period/>
It is somehow expected that:
XMLEvent event = eventReader.nextEvent();
if (event.isStartElement()) {
StartElement startElement = event.asStartElement();
switch (startElement.getName().getLocalPart()) {
case "period":
int period = Integer.parseInt(eventReader.nextEvent().asCharacters().getData())
// do something with period
default:
}
}
throws an
Exception in thread "main" java.lang.ClassCastException
com.sun.xml.internal.stream.events.EndElementEvent cannot be cast to
javax.xml.stream.events.Characters
How can I retrieve the default value of an element using StAX? Should I parse the corresponding XML Schema, too? My gut says that there should be other, more convenient solutions.