Code example for SAXSource

0
    protected void runTest() throws Throwable { 
        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setNamespaceAware(true);
        factory.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
        SAXParser parser = factory.newSAXParser();
        SAXSource source = new SAXSource(parser.getXMLReader(), new InputSource(file.getUrl().toString()));
        OMXMLParserWrapper builder;
        if (expandEntityReferences == null) {
            builder = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), source);
        } else { 
            builder = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), source,
                    expandEntityReferences.booleanValue());
        } 
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        builder.getDocument().serialize(baos);
        XMLAssertEx.assertXMLIdentical( 
                file.getUrl(), 
                new ByteArrayInputStream(baos.toByteArray()),
                expandEntityReferences == null ? false : expandEntityReferences.booleanValue());
    } 
Connect your IDE to all the code out there  Get Codota for Java