@Test public void testSkipElement() throws FileNotFoundException, XMLStreamException { File file = new File(getAbsPath("sample.xml")); InputStream stream = new BufferedInputStream(new FileInputStream(file)); XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(stream); while (!reader.isStartElement()) { reader.next(); } XMLStreamReaderTools.skipElement(reader); assertTrue(reader.isEndElement()); }
public static final void skipElement(final XMLStreamReader reader) throws XMLStreamException { final String localName = reader.getLocalName(); while (reader.hasNext()) { reader.next(); switch (reader.getEventType()) { case XMLStreamConstants.START_ELEMENT: { skipElement(reader); break; } case XMLStreamConstants.END_ELEMENT: { if (localName.equals(reader.getLocalName())) { return; } else { throw new AssertionError(reader.getLocalName()); } } case XMLStreamConstants.CHARACTERS: { break; } default: { throw new AssertionError(reader.getEventType()); } } } throw new AssertionError(); }
XMLStreamReaderTools { public static final void skipElement(final XMLStreamReader reader) throws XMLStreamException { final String localName = reader.getLocalName(); while (reader.hasNext()) { reader.next(); switch (reader.getEventType()) { case XMLStreamConstants.START_ELEMENT: { skipElement(reader); break; } case XMLStreamConstants.END_ELEMENT: { if (localName.equals(reader.getLocalName())) { return; } else { throw new AssertionError(reader.getLocalName()); } } case XMLStreamConstants.CHARACTERS: { break; } default: { throw new AssertionError(reader.getEventType()); } } } throw new AssertionError(); } }
XMLStreamReaderTools { public static final void skipElement(final XMLStreamReader reader) throws XMLStreamException { final String localName = reader.getLocalName(); while (reader.hasNext()) { reader.next(); switch (reader.getEventType()) { case XMLStreamConstants.START_ELEMENT: { skipElement(reader); break; } case XMLStreamConstants.END_ELEMENT: { if (localName.equals(reader.getLocalName())) { return; } else { throw new AssertionError(reader.getLocalName()); } } case XMLStreamConstants.CHARACTERS: { break; } default: { throw new AssertionError(reader.getEventType()); } } } throw new AssertionError(); }  }
XMLStreamReaderTools { public static final void skipElement(final XMLStreamReader reader) throws XMLStreamException { final String localName = reader.getLocalName(); while (reader.hasNext()) { reader.next(); switch (reader.getEventType()) { case XMLStreamConstants.START_ELEMENT: { skipElement(reader); break; } case XMLStreamConstants.END_ELEMENT: { if (localName.equals(reader.getLocalName())) { return; } else { throw new AssertionError(reader.getLocalName()); } } case XMLStreamConstants.CHARACTERS: { break; } default: { throw new AssertionError(reader.getEventType()); } } } throw new AssertionError(); }  static final void skipElement(final XMLStreamReader reader); }
XMLStreamReaderTools { public static final void skipElement(final XMLStreamReader reader) throws XMLStreamException { final String localName = reader.getLocalName(); while (reader.hasNext()) { reader.next(); switch (reader.getEventType()) { case XMLStreamConstants.START_ELEMENT: { skipElement(reader); break; } case XMLStreamConstants.END_ELEMENT: { if (localName.equals(reader.getLocalName())) { return; } else { throw new AssertionError(reader.getLocalName()); } } case XMLStreamConstants.CHARACTERS: { break; } default: { throw new AssertionError(reader.getEventType()); } } } throw new AssertionError(); }  static final void skipElement(final XMLStreamReader reader);  }