public static List < XMLEvent > parse ( String theValue ) { if ( isBlank ( theValue ) ) { return Collections . emptyList ( ) ; } String val = theValue . trim ( ) ; if ( ! val . startsWith ( "<" ) ) { val = XhtmlDt . DIV_OPEN_FIRST + val + "</div>" ; } boolean hasProcessingInstruction = val . startsWith ( "<?" ) ; if ( hasProcessingInstruction && val . endsWith ( "?>" ) ) { return null ; } try { ArrayList < XMLEvent > value = new ArrayList <> ( ) ; StringReader reader = new StringReader ( val ) ; XMLEventReader er = XmlUtil . createXmlReader ( reader ) ; boolean first = true ; while ( er . hasNext ( ) ) { XMLEvent next = er . nextEvent ( ) ; if ( first ) { first = false ; continue ; } if ( er . hasNext ( ) ) { // don't add the last event value . add ( next ) ; } } return value ; } catch ( XMLStreamException e ) { throw new DataFormatException ( "String does not appear to be valid XML/XHTML (error is \"" + e . getMessage ( ) + "\"): " + theValue , e ) ; } catch ( FactoryConfigurationError e ) { throw new ConfigurationException ( e ) ; } }
Parses an XML string into a set of StAX events