protected Map < String , RDFNode > readNext ( ) throws SparqlException { try { // read <result> or </results> int eventType = reader . nextTag ( ) ; // if a closing element, then it should be </results> if ( eventType == END_ELEMENT ) { // already read the final result, so clean up and return nothing if ( nameIs ( RESULTS ) ) { cleanup ( ) ; return null ; } else throw new SparqlException ( "Bad element closure with: " + reader . getLocalName ( ) ) ; } // we only expect a <result> here testOpen ( eventType , RESULT , "Expected a new result. Got :" + ( ( eventType == END_ELEMENT ) ? "/" : "" ) + reader . getLocalName ( ) ) ; Map < String , RDFNode > result = new HashMap < String , RDFNode > ( ) ; // read <binding> list while ( ( eventType = reader . nextTag ( ) ) == START_ELEMENT && nameIs ( BINDING ) ) { // get the name of the binding String name = reader . getAttributeValue ( null , VAR_NAME ) ; result . put ( name , parseValue ( ) ) ; testClose ( reader . nextTag ( ) , BINDING , "Single Binding not closed correctly" ) ; } // a non- <binding> was read, so it should have been a </result> testClose ( eventType , RESULT , "Single Result not closed correctly" ) ; return result ; } catch ( XMLStreamException e ) { throw new SparqlException ( "Error reading from XML stream" , e ) ; } }
Parse the input stream to look for a result .