@Test public void testNextTag() throws XMLStreamException { XMLEventReader reader = createXmlEventReader("<?xml version=\"1.0\"?><alice david=\"edgar\"><edgar/></alice>", ACCEPT_ALL); Assert.assertEquals(XMLStreamConstants.START_ELEMENT, reader.nextTag().getEventType()); Assert.assertEquals(XMLStreamConstants.START_ELEMENT, reader.nextTag().getEventType()); Assert.assertEquals(XMLStreamConstants.END_ELEMENT, reader.nextTag().getEventType()); Assert.assertEquals(XMLStreamConstants.END_ELEMENT, reader.nextTag().getEventType()); reader = createXmlEventReader("<?xml version=\"1.0\"?><alice david=\"edgar\"><edgar/></alice>", ACCEPT_ALL); reader.peek(); Assert.assertEquals(XMLStreamConstants.START_ELEMENT, reader.nextTag().getEventType()); reader.peek(); Assert.assertEquals(XMLStreamConstants.START_ELEMENT, reader.nextTag().getEventType()); reader.peek(); Assert.assertEquals(XMLStreamConstants.END_ELEMENT, reader.nextTag().getEventType()); reader.peek(); Assert.assertEquals(XMLStreamConstants.END_ELEMENT, reader.nextTag().getEventType()); }
@Override public XMLEvent nextTag() throws XMLStreamException { while (true) { XMLEvent event = nextEvent(); switch (event.getEventType()) { case XMLStreamConstants.START_DOCUMENT: break; case XMLStreamConstants.COMMENT: case XMLStreamConstants.PROCESSING_INSTRUCTION: case XMLStreamConstants.SPACE: break; case XMLStreamConstants.CDATA: case XMLStreamConstants.CHARACTERS: if (!event.asCharacters().isWhiteSpace()) { throw new XMLStreamException("Encountered non-whitespace text"); } break; case XMLStreamConstants.START_ELEMENT: case XMLStreamConstants.END_ELEMENT: return event; default: throw new XMLStreamException("Encountered unexpected event: " + event.getEventType()); } } }
SimpleXMLFilteredEventReader extends EventReaderDelegate { @Override public XMLEvent nextTag() throws XMLStreamException { while (true) { XMLEvent event = nextEvent(); switch (event.getEventType()) { case XMLStreamConstants.START_DOCUMENT: break; case XMLStreamConstants.COMMENT: case XMLStreamConstants.PROCESSING_INSTRUCTION: case XMLStreamConstants.SPACE: break; case XMLStreamConstants.CDATA: case XMLStreamConstants.CHARACTERS: if (!event.asCharacters().isWhiteSpace()) { throw new XMLStreamException("Encountered non-whitespace text"); } break; case XMLStreamConstants.START_ELEMENT: case XMLStreamConstants.END_ELEMENT: return event; default: throw new XMLStreamException("Encountered unexpected event: " + event.getEventType()); } } } }
SimpleXMLFilteredEventReader extends EventReaderDelegate { @Override public XMLEvent nextTag() throws XMLStreamException { while (true) { XMLEvent event = nextEvent(); switch (event.getEventType()) { case XMLStreamConstants.START_DOCUMENT: break; case XMLStreamConstants.COMMENT: case XMLStreamConstants.PROCESSING_INSTRUCTION: case XMLStreamConstants.SPACE: break; case XMLStreamConstants.CDATA: case XMLStreamConstants.CHARACTERS: if (!event.asCharacters().isWhiteSpace()) { throw new XMLStreamException("Encountered non-whitespace text"); } break; case XMLStreamConstants.START_ELEMENT: case XMLStreamConstants.END_ELEMENT: return event; default: throw new XMLStreamException("Encountered unexpected event: " + event.getEventType()); } } } SimpleXMLFilteredEventReader(XMLEventReader reader, EventFilter filter); }
SimpleXMLFilteredEventReader extends EventReaderDelegate { @Override public XMLEvent nextTag() throws XMLStreamException { while (true) { XMLEvent event = nextEvent(); switch (event.getEventType()) { case XMLStreamConstants.START_DOCUMENT: break; case XMLStreamConstants.COMMENT: case XMLStreamConstants.PROCESSING_INSTRUCTION: case XMLStreamConstants.SPACE: break; case XMLStreamConstants.CDATA: case XMLStreamConstants.CHARACTERS: if (!event.asCharacters().isWhiteSpace()) { throw new XMLStreamException("Encountered non-whitespace text"); } break; case XMLStreamConstants.START_ELEMENT: case XMLStreamConstants.END_ELEMENT: return event; default: throw new XMLStreamException("Encountered unexpected event: " + event.getEventType()); } } } 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(); }
SimpleXMLFilteredEventReader extends EventReaderDelegate { @Override public XMLEvent nextTag() throws XMLStreamException { while (true) { XMLEvent event = nextEvent(); switch (event.getEventType()) { case XMLStreamConstants.START_DOCUMENT: break; case XMLStreamConstants.COMMENT: case XMLStreamConstants.PROCESSING_INSTRUCTION: case XMLStreamConstants.SPACE: break; case XMLStreamConstants.CDATA: case XMLStreamConstants.CHARACTERS: if (!event.asCharacters().isWhiteSpace()) { throw new XMLStreamException("Encountered non-whitespace text"); } break; case XMLStreamConstants.START_ELEMENT: case XMLStreamConstants.END_ELEMENT: return event; default: throw new XMLStreamException("Encountered unexpected event: " + event.getEventType()); } } } 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();  }