List of usage examples for javax.xml.stream XMLStreamReader getName
public QName getName();
From source file:Main.java
public static void main(String[] args) throws Exception { URLConnection connection = new URL("http://api.androidhive.info/pizza/?format=xml").openConnection(); InputStream inputStream = connection.getInputStream(); XMLStreamReader streamReader = XMLInputFactory.newInstance().createXMLStreamReader(inputStream, "UTF-8"); while (streamReader.hasNext()) if (streamReader.next() == XMLStreamConstants.START_ELEMENT) System.out.println("START_ELEMENT " + streamReader.getName()); }
From source file:Main.java
public static void main(String args[]) throws Exception { XMLInputFactory xmlif = XMLInputFactory.newInstance(); XMLStreamReader xmlsr = xmlif.createXMLStreamReader(new FileReader("points.xml")); int eventType; while (xmlsr.hasNext()) { eventType = xmlsr.next();/*from w ww. jav a 2 s.c om*/ switch (eventType) { case XMLEvent.START_ELEMENT: System.out.println(xmlsr.getName()); break; case XMLEvent.CHARACTERS: System.out.println(xmlsr.getText()); break; default: break; } } }
From source file:Main.java
public static boolean isStartOfElement(final XMLStreamReader reader, final String name) { return isStartElement(reader) && reader.getName().getLocalPart().equals(name); }
From source file:Main.java
/** * Raises a new unexpected element exception. * @param reader XML reader./*from w ww. j a v a 2s.c o m*/ * @return Exception. */ public static XMLStreamException unexpectedElementException(XMLStreamReader reader) { return new XMLStreamException(String.format("Unexpected element: %s.", reader.getName().toString())); }
From source file:Main.java
public static boolean isEndOfElement(final XMLStreamReader reader, final String name) { return reader.getEventType() == XMLStreamReader.END_ELEMENT && reader.getName().getLocalPart().equals(name); }
From source file:Main.java
public static void printStartElement(XMLStreamReader xmlr) { if (xmlr.isStartElement()) { System.out.print("<" + xmlr.getName().toString()); printAttributes(xmlr);//from w w w . j a va 2 s. com // System.out.print(</codeTitle><cnTitle></cnTitle><codeKeywords></codeKeywords><codeComments></codeComments>"); } }
From source file:Main.java
/** * Raises a new unexpected element exception, reporting the single expected element. * @param reader Reader.//w ww . ja v a 2 s . co m * @param expected Expected element. * @return Exception. */ public static XMLStreamException unexpectedElementException(XMLStreamReader reader, String expected) { return new XMLStreamException( String.format("Unexpected element. Expected %s, got %s.", expected, reader.getName().toString())); }
From source file:StaxCursorTest.java
private static void printEndElement(XMLStreamReader xmlr) { if (xmlr.isEndElement()) { System.out.print("</" + xmlr.getName().toString() + ">"); }//from w w w . j a v a 2 s . c o m }
From source file:StaxCursorTest.java
private static void printStartElement(XMLStreamReader xmlr) { if (xmlr.isStartElement()) { System.out.print("<" + xmlr.getName().toString()); printAttributes(xmlr);/*from w w w . j av a 2 s .co m*/ System.out.print(">"); } }
From source file:Main.java
@SuppressWarnings("empty-statement") public static Optional<String> nextTag(XMLStreamReader reader) throws XMLStreamException { while (reader.hasNext() && reader.next() != XMLStreamReader.START_ELEMENT) ;/*from ww w.ja v a 2 s . c om*/ if (reader.getEventType() == XMLStreamReader.END_DOCUMENT) { return Optional.empty(); } else { return Optional.of(reader.getName().getLocalPart()); } }