SimpleXMLFilteredEventReader extends EventReaderDelegate { @Override public XMLEvent nextEvent() throws XMLStreamException { if (hasNext()) { XMLEvent event = getParent().nextEvent(); currentEventType = event.getEventType(); return event; } throw new XMLStreamException("no more events"); } SimpleXMLFilteredEventReader(XMLEventReader reader, EventFilter filter); @Override void setParent(XMLEventReader reader); @Override boolean hasNext(); @Override XMLEvent peek(); @Override Object next(); @Override XMLEvent nextEvent(); @Override String getElementText(); @Override XMLEvent nextTag();  }
@Test public void testStartEndDocument() throws XMLStreamException { XMLEventReader reader = createXmlEventReader("<? xml version=\"1.0\" ?>", ACCEPT_ALL); Assert.assertEquals(XMLStreamConstants.START_DOCUMENT, reader.nextEvent().getEventType()); Assert.assertEquals(XMLStreamConstants.END_DOCUMENT, reader.nextEvent().getEventType()); }
@Test public void testStartEndElement() throws XMLStreamException { XMLEventReader reader = createXmlEventReader("<alice/>", ACCEPT_ALL); Assert.assertEquals(XMLStreamConstants.START_ELEMENT, reader.nextEvent().getEventType()); Assert.assertEquals(XMLStreamConstants.END_ELEMENT, reader.nextEvent().getEventType()); reader = createXmlEventReader("<alice></alice>", ACCEPT_ALL); Assert.assertEquals(XMLStreamConstants.START_ELEMENT, reader.nextEvent().getEventType()); Assert.assertEquals(XMLStreamConstants.END_ELEMENT, reader.nextEvent().getEventType()); }
@Test public void testCharactersCData() throws XMLStreamException { XMLEventReader reader = createXmlEventReader("<alice>bob</alice>", ACCEPT_ALL); Assert.assertEquals(XMLStreamConstants.START_ELEMENT, reader.nextEvent().getEventType()); Assert.assertEquals(XMLStreamConstants.CHARACTERS, reader.nextEvent().getEventType()); Assert.assertEquals(XMLStreamConstants.END_ELEMENT, reader.nextEvent().getEventType()); reader = createXmlEventReader("<alice><![CDATA[bob]]></alice>", ACCEPT_ALL); Assert.assertEquals(XMLStreamConstants.START_ELEMENT, reader.nextEvent().getEventType()); Assert.assertEquals(XMLStreamConstants.CDATA, reader.nextEvent().getEventType()); Assert.assertEquals(XMLStreamConstants.END_ELEMENT, reader.nextEvent().getEventType()); }
@Test public void testCharactersCData2() throws XMLStreamException { XMLEventReader reader = createXmlEventReader("<alice>bob</alice>", new TypeFilter(XMLStreamConstants.CHARACTERS)); Assert.assertEquals(XMLStreamConstants.START_ELEMENT, reader.nextEvent().getEventType()); Assert.assertEquals(XMLStreamConstants.END_ELEMENT, reader.nextEvent().getEventType()); reader = createXmlEventReader("<alice><![CDATA[bob]]></alice>", new TypeFilter(XMLStreamConstants.CDATA)); Assert.assertEquals(XMLStreamConstants.START_ELEMENT, reader.nextEvent().getEventType()); Assert.assertEquals(XMLStreamConstants.END_ELEMENT, reader.nextEvent().getEventType()); }