public static boolean rootElementMatches ( FileResource fileResource , String path , String expectedRootElement ) throws IOException { try ( InputStream stream = fileResource . createStream ( ) ) { XMLStreamReader reader = factory . createXMLStreamReader ( stream ) ; while ( reader . hasNext ( ) ) { int event = reader . next ( ) ; switch ( event ) { case XMLStreamConstants . START_ELEMENT : String rootElement = reader . getLocalName ( ) ; return expectedRootElement . equals ( rootElement ) ; } } } catch ( XMLStreamException e ) { LOGGER . warn ( "Cannot parse XML file '{}'." , path ) ; } return false ; }
Matches a file resource for being an XML file with a specific root element .