Thursday, January 28, 2010

Error: elementGetText() function expects text only elment but START_ELEMENT was encountered

If you see the following exception,
====================================================================
javax.xml.stream.XMLStreamException: ParseError at [row,col]:
Message: elementGetText() function expects text only elment but START_ELEMENT was encountered.
at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.getElementText(Unknown Source)
at com.sun.xml.internal.stream.XMLEventReaderImpl.getElementText(Unknown Source)
at javax.xml.stream.util.EventReaderDelegate.getElementText(Unknown Source)
=====================================================================

it means that your STAX based parser is not handling the embedded xml properly. Your parser is expecting a regular text element and doing XMLEventReader.getElementText() call.

Solutions:
1) Bad: You can convert all "<" of your embedded xml to & l t ; (characters brought together).
2) Good: Let the parser peek at the next event and see if it is embedded xml and handle properly.

No comments: