Java Code Examples for org.xml.sax.XMLReader#setErrorHandler()

The following examples show how to use org.xml.sax.XMLReader#setErrorHandler() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: S3Util.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public ListAllMyBucketsResponse(HttpURLConnection connection) throws IOException {
    super(connection);
    if (connection.getResponseCode() < 400) {
        try {
            XMLReader xr = Utils.createXMLReader();
            ListAllMyBucketsHandler handler = new ListAllMyBucketsHandler();
            xr.setContentHandler(handler);
            xr.setErrorHandler(handler);

            xr.parse(new InputSource(connection.getInputStream()));
            this.entries = handler.getEntries();
        } catch (SAXException e) {
            throw HostControllerLogger.ROOT_LOGGER.errorParsingBucketListings(e);
        }
    }
}
 
Example 2
Source File: SAXParser.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parse the content given {@link org.xml.sax.InputSource}
 * as XML using the specified
 * {@link org.xml.sax.helpers.DefaultHandler}.
 *
 * @param is The InputSource containing the content to be parsed.
 * @param dh The SAX DefaultHandler to use.
 *
 * @throws IllegalArgumentException If the <code>InputSource</code> object
 *   is <code>null</code>.
 * @throws IOException If any IO errors occur.
 * @throws SAXException If any SAX errors occur during processing.
 *
 * @see org.xml.sax.DocumentHandler
 */
public void parse(InputSource is, DefaultHandler dh)
    throws SAXException, IOException {
    if (is == null) {
        throw new IllegalArgumentException("InputSource cannot be null");
    }

    XMLReader reader = this.getXMLReader();
    if (dh != null) {
        reader.setContentHandler(dh);
        reader.setEntityResolver(dh);
        reader.setErrorHandler(dh);
        reader.setDTDHandler(dh);
    }
    reader.parse(is);
}
 
Example 3
Source File: Filter.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Parse and load the given filter file.
 *
 * @param fileName
 *            name of the filter file
 * @throws IOException
 * @throws SAXException
 * @throws ParserConfigurationException
 */
private void parse(String fileName, @WillClose InputStream stream) throws IOException, SAXException, ParserConfigurationException {
    try {
        SAXBugCollectionHandler handler = new SAXBugCollectionHandler(this, new File(fileName));
        SAXParserFactory parserFactory = SAXParserFactory.newInstance();
        parserFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
        parserFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", Boolean.TRUE);
        parserFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", Boolean.FALSE);
        parserFactory.setFeature("http://xml.org/sax/features/external-general-entities", Boolean.FALSE);
        parserFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", Boolean.FALSE);
        SAXParser parser = parserFactory.newSAXParser();
        XMLReader xr = parser.getXMLReader();
        xr.setContentHandler(handler);
        xr.setErrorHandler(handler);
        Reader reader = Util.getReader(stream);
        xr.parse(new InputSource(reader));
    } finally {
        Util.closeSilently(stream);
    }
}
 
Example 4
Source File: EdfiRecordParserImpl2.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
private void parseAndValidate(InputStream input, Schema schema) throws XmlParseException, IOException {
    ValidatorHandler vHandler = schema.newValidatorHandler();
    vHandler.setContentHandler(this);
    vHandler.setErrorHandler(this);

    InputSource is = new InputSource(new InputStreamReader(input, "UTF-8"));
    is.setEncoding("UTF-8");

    try {
        XMLReader parser = XMLReaderFactory.createXMLReader();
        parser.setContentHandler(vHandler);
        parser.setErrorHandler(this);

        vHandler.setFeature("http://apache.org/xml/features/continue-after-fatal-error", false);

        parser.setFeature("http://apache.org/xml/features/validation/id-idref-checking", false);
        parser.setFeature("http://apache.org/xml/features/continue-after-fatal-error", false);
        parser.setFeature("http://xml.org/sax/features/external-general-entities", false);
        parser.setFeature("http://xml.org/sax/features/external-parameter-entities", false);

        parser.parse(is);
    } catch (SAXException e) {
        throw new XmlParseException(e.getMessage(), e);
    }
}
 
Example 5
Source File: S3Util.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Parse the response to a ?location query.
 */
public LocationResponse(HttpURLConnection connection) throws IOException {
    super(connection);
    if (connection.getResponseCode() < 400) {
        try {
            XMLReader xr = Utils.createXMLReader();
            LocationResponseHandler handler = new LocationResponseHandler();
            xr.setContentHandler(handler);
            xr.setErrorHandler(handler);

            xr.parse(new InputSource(connection.getInputStream()));
            this.location = handler.loc;
        } catch (SAXException e) {
            throw HostControllerLogger.ROOT_LOGGER.errorParsingBucketListings(e);
        }
    } else {
        this.location = "<error>";
    }
}
 
Example 6
Source File: SAXParser.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Parse the content given {@link org.xml.sax.InputSource}
 * as XML using the specified
 * {@link org.xml.sax.helpers.DefaultHandler}.
 *
 * @param is The InputSource containing the content to be parsed.
 * @param dh The SAX DefaultHandler to use.
 *
 * @throws IllegalArgumentException If the <code>InputSource</code> object
 *   is <code>null</code>.
 * @throws IOException If any IO errors occur.
 * @throws SAXException If any SAX errors occur during processing.
 *
 * @see org.xml.sax.DocumentHandler
 */
public void parse(InputSource is, DefaultHandler dh)
    throws SAXException, IOException {
    if (is == null) {
        throw new IllegalArgumentException("InputSource cannot be null");
    }

    XMLReader reader = this.getXMLReader();
    if (dh != null) {
        reader.setContentHandler(dh);
        reader.setEntityResolver(dh);
        reader.setErrorHandler(dh);
        reader.setDTDHandler(dh);
    }
    reader.parse(is);
}
 
Example 7
Source File: ServiceProvisioningServiceBeanImportExportSchemaIT.java    From development with Apache License 2.0 5 votes vote down vote up
private void verifyXML(byte[] xml) throws IOException, SAXException,
        ParserConfigurationException {
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(true);

    SchemaFactory sf = SchemaFactory
            .newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

    ClassLoader classLoader = Thread.currentThread()
            .getContextClassLoader();
    if (classLoader == null) {
        classLoader = getClass().getClassLoader();
    }

    final Schema schema;
    try (InputStream inputStream = ResourceLoader.getResourceAsStream(
            getClass(), "TechnicalServices.xsd")) {
        schema = sf.newSchema(new StreamSource(inputStream));
    }
    spf.setSchema(schema);

    SAXParser saxParser = spf.newSAXParser();
    XMLReader reader = saxParser.getXMLReader();
    ErrorHandler errorHandler = new MyErrorHandler();
    reader.setErrorHandler(errorHandler);
    reader.parse(new InputSource(new ByteArrayInputStream(xml)));
}
 
Example 8
Source File: XSLTransformationDialog.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 转换文件
 * @param strSourcePath
 *            源文件路径
 * @param strXSLPath
 *            XSL 文件路径
 * @param strTargetPath
 *            转变文件路径
 * @throws Exception
 *             ;
 */
private void transform(String strSourcePath, String strXSLPath, String strTargetPath) throws Exception {
	TransformerFactory tfactory = TransformerFactory.newInstance();
	String catalogPath = PluginUtil.getCataloguePath();

	if (tfactory.getFeature(SAXSource.FEATURE)) {
		// Standard way of creating an XMLReader in JAXP 1.1.
		SAXParserFactory pfactory = SAXParserFactory.newInstance();
		pfactory.setNamespaceAware(true); // Very important!
		// Turn on validation.
		// pfactory.setValidating(true);
		// Get an XMLReader.
		XMLReader reader = pfactory.newSAXParser().getXMLReader();
		reader.setEntityResolver(new Catalogue(catalogPath));

		// Instantiate an error handler (see the Handler inner class below)
		// that will report any
		// errors or warnings that occur as the XMLReader is parsing the XML
		// input.
		reader.setErrorHandler(new HSErrorHandler());

		// Standard way of creating a transformer from a URL.
		Transformer t = tfactory.newTransformer(new StreamSource(strXSLPath));

		// Specify a SAXSource that takes both an XMLReader and a URL.
		SAXSource source = new SAXSource(reader, new InputSource(strSourcePath));

		// Transform to a file.
		t.transform(source, new StreamResult(strTargetPath));

	} else {
		throw new Exception(Messages.getString("dialog.XSLTransformationDialog.msg6")); //$NON-NLS-1$
	}
}
 
Example 9
Source File: AbstractModelReader.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Parses the given specification and loads all includes specified in the files.
 * This implementation does not check for loops in the include files.
 *
 * @param resource  the url of the xml specification.
 * @param isInclude  an include?
 * 
 * @throws org.jfree.xml.util.ObjectDescriptionException if an error occured which prevented the
 * loading of the specifications.
 */
protected void parseXmlDocument(final URL resource, final boolean isInclude)
    throws ObjectDescriptionException {
    
    try {
        final InputStream in = new BufferedInputStream(resource.openStream());
        final SAXParserFactory factory = SAXParserFactory.newInstance();
        final SAXParser saxParser = factory.newSAXParser();
        final XMLReader reader = saxParser.getXMLReader();

        final SAXModelHandler handler = new SAXModelHandler(resource, isInclude);
        try {
            reader.setProperty
                ("http://xml.org/sax/properties/lexical-handler",
                    getCommentHandler());
        }
        catch (SAXException se) {
            Log.debug("Comments are not supported by this SAX implementation.");
        }
        reader.setContentHandler(handler);
        reader.setDTDHandler(handler);
        reader.setErrorHandler(handler);
        reader.parse(new InputSource(in));
        in.close();
    }
    catch (Exception e) {
        // unable to init
        Log.warn("Unable to load factory specifications", e);
        throw new ObjectDescriptionException("Unable to load object factory specs.", e);
    }
}
 
Example 10
Source File: RSSFeed.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected List<FeedItem> buildItemList() throws SAXException, ParserConfigurationException, IOException {
    XMLReader reader = XMLUtil.createXMLReader( false, true );
    FeedHandler handler = new FeedHandler( getMaxItemCount() );
    reader.setContentHandler( handler );
    reader.setEntityResolver( new RSSEntityResolver() );
    reader.setErrorHandler( new ErrorCatcher() );

    InputSource is = findInputSource(new URL(url));
    reader.parse( is );

    return handler.getItemList();
}
 
Example 11
Source File: Bug4848653.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test() throws IOException, SAXException, ParserConfigurationException {
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setValidating(false);
    SAXParser parser = factory.newSAXParser();
    parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", XMLConstants.W3C_XML_SCHEMA_NS_URI);

    String filename = XML_DIR + "Bug4848653.xml";
    InputSource is = new InputSource(filenameToURL(filename));
    XMLReader xmlReader = parser.getXMLReader();
    xmlReader.setErrorHandler(new MyErrorHandler());
    xmlReader.parse(is);
}
 
Example 12
Source File: CustomSAXSVGDocumentFactory.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected Document createDocument(InputSource is) throws IOException {
    try {
        final XMLReader parser = new SAXParser();

        parser.setContentHandler(this);
        parser.setDTDHandler(this);
        parser.setEntityResolver(this);
        parser.setErrorHandler((errorHandler == null) ? this : errorHandler);

        parser.setFeature("http://xml.org/sax/features/namespaces",
                true);
        parser.setFeature("http://xml.org/sax/features/namespace-prefixes",
                true);
        parser.setFeature("http://xml.org/sax/features/validation",
                isValidating);
        parser.setProperty("http://xml.org/sax/properties/lexical-handler",
                this);
        parser.parse(is);
    } catch (final SAXException e) {
        final Exception ex = e.getException();
        if (ex != null && ex instanceof InterruptedIOException) {
            throw (InterruptedIOException) ex;
        }
        throw new IOException(e.getMessage());
    }

    currentNode = null;
    final Document ret = document;
    document = null;
    locator = null;
    return ret;
}
 
Example 13
Source File: ValidateMojo.java    From xml-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Called for validating a single file.
 * 
 * @param pResolver The resolver to use for loading external entities.
 * @param pValidationSet The validators configuration.
 * @param pFile The file to validate.
 * @throws IOException An I/O error occurred.
 * @throws SAXException Parsing the file failed.
 * @throws ParserConfigurationException Creating an XML parser failed.
 */
private void parse( Resolver pResolver, ValidationSet pValidationSet, File pFile , ErrorHandler errorHandler)
    throws IOException, SAXException, ParserConfigurationException
{
    XMLReader xr = newSAXParserFactory( pValidationSet ).newSAXParser().getXMLReader();
    if ( pResolver != null )
    {
        xr.setEntityResolver( pResolver );
    }
    xr.setErrorHandler( errorHandler );
    xr.parse( pFile.toURI().toURL().toExternalForm() );
}
 
Example 14
Source File: ConfigReader.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parses an xml config file and returns a Config object.
 *
 * @param xmlFile
 *        The xml config file which is passed by the user to annotation processing
 * @return
 *        A non null Config object
 */
private Config parseAndGetConfig (File xmlFile, ErrorHandler errorHandler, boolean disableSecureProcessing) throws SAXException, IOException {
    XMLReader reader;
    try {
        SAXParserFactory factory = XmlFactory.createParserFactory(disableSecureProcessing);
        reader = factory.newSAXParser().getXMLReader();
    } catch (ParserConfigurationException e) {
        // in practice this will never happen
        throw new Error(e);
    }
    NGCCRuntimeEx runtime = new NGCCRuntimeEx(errorHandler);

    // set up validator
    ValidatorHandler validator = configSchema.newValidator();
    validator.setErrorHandler(errorHandler);

    // the validator will receive events first, then the parser.
    reader.setContentHandler(new ForkContentHandler(validator,runtime));

    reader.setErrorHandler(errorHandler);
    Config config = new Config(runtime);
    runtime.setRootHandler(config);
    reader.parse(new InputSource(xmlFile.toURL().toExternalForm()));
    runtime.reset();

    return config;
}
 
Example 15
Source File: TMRAPTestCaseContentHandler.java    From ontopia with Apache License 2.0 5 votes vote down vote up
public void register(XMLReader parser) {
  parser.setContentHandler(this);
  ErrorHandler _ehandler = parser.getErrorHandler();
  if (_ehandler == null || (_ehandler instanceof DefaultHandler))
    parser.setErrorHandler(getDefaultErrorHandler());
  ehandler = parser.getErrorHandler();
}
 
Example 16
Source File: JDBCDriverConvertor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static JDBCDriver readDriverFromFile(FileObject fo) throws IOException, MalformedURLException {
    Handler handler = new Handler();
    
    // parse the XM file
    try {
        XMLReader reader = XMLUtil.createXMLReader();
        InputSource is = new InputSource(fo.getInputStream());
        is.setSystemId(fo.toURL().toExternalForm());
        reader.setContentHandler(handler);
        reader.setErrorHandler(handler);
        reader.setEntityResolver(EntityCatalog.getDefault());

        reader.parse(is);
    } catch (SAXException ex) {
        throw new IOException(ex.getMessage());
    }
    
    // read the driver from the handler
    URL[] urls = new URL[handler.urls.size()];
    int j = 0;
    for (Iterator i = handler.urls.iterator(); i.hasNext(); j++) {
        urls[j] = new URL((String)i.next());
    }
    if (checkClassPathDrivers(handler.clazz, urls) == false) {
        return null;
    }
    
    if (handler.displayName == null) {
        handler.displayName = handler.name;
    }
    return JDBCDriver.create(handler.name, handler.displayName, handler.clazz, urls);
}
 
Example 17
Source File: XMLFileSystem.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private synchronized void setXmlUrls(URL[] urls, boolean validate)
throws IOException, PropertyVetoException {
    if (urls == null) {
        throw new NullPointerException("Null URL list"); // NOI18N
    }
    Collection<URL> asList = Arrays.asList(urls);
    if (asList.contains(null)) {
        throw new NullPointerException("Null URL list member: " + asList); // NOI18N
    }

    ResourceElem rootElem;
    String oldDisplayName = getDisplayName();

    if (urls.length == 0) {
        urlsToXml = urls;
        refreshChildrenInAtomicAction((AbstractFolder) getRoot(), rootElem = new ResourceElem(true, urls)); // NOI18N
        rootElem = null;

        return;
    }

    Handler handler = new Handler(DTD_MAP, rootElem = new ResourceElem(true, urls), validate); // NOI18N        

    try {
        _setSystemName("XML_" + urls[0].toExternalForm().replace('/','-')); // NOI18N
    } catch (PropertyVetoException pvx) {
        rootElem = null;
        throw pvx;
    }

    URL act = null;

    try {
        XMLReader xp = XMLUtil.createXMLReader(validate, false);
        xp.setEntityResolver(handler);
        xp.setContentHandler(handler);
        xp.setErrorHandler(handler);

        for (int index = 0; index < urls.length; index++) {
            act = urls[index];
            handler.urlContext = act;

            String systemId = act.toExternalForm();

            xp.parse(systemId);
        }
        urlsToXml = urls.clone();
        refreshChildrenInAtomicAction((AbstractFolder) getRoot(), rootElem);
    } catch (IOException iox) {
        Exceptions.attachMessage(iox, Arrays.toString(urls));
        throw iox;
    } catch (Exception e) {
        throw (IOException) new IOException(act + ": " + e.toString()).initCause(e); // NOI18N
    } finally {
        rootElem = null;
    }

    firePropertyChange(PROP_DISPLAY_NAME, oldDisplayName, getDisplayName());
}
 
Example 18
Source File: TestPrintXML.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String... args) throws Throwable {

        Path recordingFile = ExecuteHelper.createProfilingRecording().toAbsolutePath();

        OutputAnalyzer output = ExecuteHelper.jfr("print", "--xml", "--stack-depth", "9999", recordingFile.toString());
        System.out.println(recordingFile);
        String xml = output.getStdout();

        SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = schemaFactory.newSchema(new File(System.getProperty("test.src"), "jfr.xsd"));

        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setSchema(schema);
        factory.setNamespaceAware(true);

        SAXParser sp = factory.newSAXParser();
        XMLReader xr = sp.getXMLReader();
        RecordingHandler handler = new RecordingHandler();
        xr.setContentHandler(handler);
        xr.setErrorHandler(handler);
        xr.parse(new InputSource(new StringReader(xml)));

        // Verify that all data was written correctly
        List<RecordedEvent> events = RecordingFile.readAllEvents(recordingFile);
        Collections.sort(events, (e1, e2) -> e1.getEndTime().compareTo(e2.getEndTime()));
        Iterator<RecordedEvent> it = events.iterator();
        for (XMLEvent xmlEvent : handler.events) {
            RecordedEvent re = it.next();
            if (!compare(re, xmlEvent.values)) {
                System.out.println("Expected:");
                System.out.println("----------------------");
                System.out.println(re);
                System.out.println();
                System.out.println("Was (XML)");
                System.out.println("----------------------");
                System.out.println(xmlEvent);
                System.out.println();
                throw new Exception("Event doesn't match");
            }
        }

    }
 
Example 19
Source File: AlchemyEntityOccurrenceExtractor.java    From wandora with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean _extractTopicsFrom(String occurrenceData, Topic masterTopic, TopicMap topicMap, Wandora wandora) throws Exception {
    AlchemyEntityExtractor extractor = new AlchemyEntityExtractor();
    extractor.setToolLogger(this.getDefaultLogger());
    extractor.setMasterSubject(masterTopic);
    String apikey = extractor.solveAPIKey(wandora);
    String masterTerm = null;
    if(masterTopic != null) masterTerm = masterTopic.getOneSubjectIdentifier().toExternalForm();
    if(occurrenceData != null && occurrenceData.length() > 0) {
        if(apikey != null) apikey = apikey.trim();
        if(apikey != null && apikey.length() > 0) {
            String content = null;
            content = occurrenceData;

            String alchemyURL = AlchemyEntityExtractor.ALCHEMY_URL+"calls/text/TextGetNamedEntities"; // ?apikey="+apikey+"&linkedData=1&disambiguate=1&outputMode=xml&text="+URLEncoder.encode(content, "utf-8");
            String alchemyData = "apikey="+URLEncoder.encode(apikey, "utf-8")+"&linkedData=1&disambiguate=1&outputMode=xml&text="+URLEncoder.encode(content, "utf-8");
            String result = AlchemyEntityExtractor.sendRequest(new URL(alchemyURL), alchemyData, "application/x-www-form-urlencoded", "POST");

            // System.out.println("----------------------------------------");
            // System.out.println("Occurrence == "+content);
            // System.out.println("Alchemy returned == "+result);

            javax.xml.parsers.SAXParserFactory factory=javax.xml.parsers.SAXParserFactory.newInstance();
            factory.setNamespaceAware(true);
            factory.setValidating(false);
            javax.xml.parsers.SAXParser parser=factory.newSAXParser();
            XMLReader reader=parser.getXMLReader();
            AlchemyEntityExtractor.AlchemyEntityParser parserHandler = extractor.new AlchemyEntityParser(masterTerm, content, topicMap, extractor);
            reader.setContentHandler(parserHandler);
            reader.setErrorHandler(parserHandler);
            try {
                reader.parse(new InputSource(new StringReader(result)));
            }
            catch(Exception e){
                if(!(e instanceof SAXException) || !e.getMessage().equals("User interrupt")) log(e);
            }
        }
        else {
            log("No valid API key given! Aborting!");
        }
    }
    else {
        log("No valid data given! Aborting!");
    }
    return true;
}
 
Example 20
Source File: TestPrintXML.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String... args) throws Throwable {

        Path recordingFile = ExecuteHelper.createProfilingRecording().toAbsolutePath();

        OutputAnalyzer output = ExecuteHelper.jfr("print", "--xml", "--stack-depth", "9999", recordingFile.toString());
        System.out.println(recordingFile);
        String xml = output.getStdout();

        SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = schemaFactory.newSchema(new File(System.getProperty("test.src"), "jfr.xsd"));

        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setSchema(schema);
        factory.setNamespaceAware(true);

        SAXParser sp = factory.newSAXParser();
        XMLReader xr = sp.getXMLReader();
        RecordingHandler handler = new RecordingHandler();
        xr.setContentHandler(handler);
        xr.setErrorHandler(handler);
        xr.parse(new InputSource(new StringReader(xml)));

        // Verify that all data was written correctly
        List<RecordedEvent> events = RecordingFile.readAllEvents(recordingFile);
        Collections.sort(events, (e1, e2) -> e1.getEndTime().compareTo(e2.getEndTime()));
        Iterator<RecordedEvent> it = events.iterator();
        for (XMLEvent xmlEvent : handler.events) {
            RecordedEvent re = it.next();
            if (!compare(re, xmlEvent.values)) {
                System.out.println("Expected:");
                System.out.println("----------------------");
                System.out.println(re);
                System.out.println();
                System.out.println("Was (XML)");
                System.out.println("----------------------");
                System.out.println(xmlEvent);
                System.out.println();
                throw new Exception("Event doesn't match");
            }
        }

    }