StartElement peekAtNextEventIfStartElement()
throws ThreddsXmlParserException
{
if ( ! this.reader.hasNext() )
throw new ThreddsXmlParserException( "XMLEventReader has no further events." );
StartElement startElement = null;
while ( this.reader.hasNext() )
{
XMLEvent event = null;
try
{
event = this.reader.peek();
}
catch (XMLStreamException e)
{
String msg = "Problem reading from XMLEventReader.";
ThreddsXmlParserIssue issue = StaxThreddsXmlParserUtils
.createIssueForException( msg, this.reader, e);
log.error("peekAtNextEventIfStartElement(): " + issue.getMessage());
// ToDo Gather issues rather than throw exception.
throw new ThreddsXmlParserException(issue);
}
if (event.isStartElement())
{
startElement = event.asStartElement();
break;
}
else if( event.isCharacters() && event.asCharacters().isWhiteSpace())
{
// Skip any whitespace characters.
this.reader.next();
}
else
{
String msg = "Expecting StartElement for next event [" + event.getClass().getName() + "]";
ThreddsXmlParserIssue issue = StaxThreddsXmlParserUtils
.createIssueForUnexpectedEvent( msg, ThreddsXmlParserIssue.Severity.FATAL, this.reader,event );
log.error( "peekAtNextEventIfStartElement(): " + issue.getMessage());
// ToDo Gather issues rather than throw exception.
throw new ThreddsXmlParserException( issue );
}
}
return startElement;
}