Search in sources :

Example 1 with ElementSelectionFilter

use of aQute.libg.sax.filters.ElementSelectionFilter in project bnd by bndtools.

the class TestSAXFilters method testSelectionFilter.

public void testSelectionFilter() throws Exception {
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    ElementSelectionFilter filter = new ElementSelectionFilter() {

        @Override
        protected boolean select(int depth, String uri, String localName, String qName, Attributes attribs) {
            return !"e".equals(qName);
        }
    };
    XMLReader reader = SAXUtil.buildPipeline(new StreamResult(output), filter);
    reader.parse(new InputSource(new ByteArrayInputStream(SAMPLE4.getBytes())));
    assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><root c=\"3\"><a><b><c><d/></c></b></a></root>", output.toString());
}
Also used : InputSource(org.xml.sax.InputSource) StreamResult(javax.xml.transform.stream.StreamResult) ByteArrayInputStream(java.io.ByteArrayInputStream) Attributes(org.xml.sax.Attributes) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ElementSelectionFilter(aQute.libg.sax.filters.ElementSelectionFilter) XMLReader(org.xml.sax.XMLReader)

Aggregations

ElementSelectionFilter (aQute.libg.sax.filters.ElementSelectionFilter)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 StreamResult (javax.xml.transform.stream.StreamResult)1 Attributes (org.xml.sax.Attributes)1 InputSource (org.xml.sax.InputSource)1 XMLReader (org.xml.sax.XMLReader)1