List of usage examples for javax.xml.stream XMLStreamReader next
public int next() throws XMLStreamException;
From source file:MainClass.java
public static void main(String[] args) throws Exception { File file = new File("test.xml"); XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader reader = inputFactory.createXMLStreamReader(new FileInputStream(file)); while (reader.getEventType() == 6) reader.next(); int eventTypeID = reader.next(); System.out.println("Hello " + reader.getText()); }
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:StAXTest.java
public static void main(String[] args) throws Exception { String urlString;// ww w. j ava 2s . c o m if (args.length == 0) { urlString = "http://www.w3c.org"; System.out.println("Using " + urlString); } else urlString = args[0]; URL url = new URL(urlString); InputStream in = url.openStream(); XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader parser = factory.createXMLStreamReader(in); while (parser.hasNext()) { int event = parser.next(); if (event == XMLStreamConstants.START_ELEMENT) { if (parser.getLocalName().equals("a")) { String href = parser.getAttributeValue(null, "href"); if (href != null) System.out.println(href); } } } }
From source file:Main.java
public static void main(String[] args) throws Exception { XMLInputFactory factory = XMLInputFactory.newInstance(); Reader fileReader = new FileReader("source.xml"); XMLStreamReader reader = factory.createXMLStreamReader(fileReader); while (reader.hasNext()) { process(reader);//from ww w.j a va2 s . c o m reader.next(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { XMLInputFactory factory = XMLInputFactory.newInstance(); Reader fileReader = new StringReader(getXMLData()); XMLStreamReader reader = factory.createXMLStreamReader(fileReader); while (reader.hasNext()) { process(reader);// ww w . j a va 2s . co m reader.next(); } }
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(); switch (eventType) { case XMLEvent.START_ELEMENT: System.out.println(xmlsr.getName()); break; case XMLEvent.CHARACTERS: System.out.println(xmlsr.getText()); break; default:// ww w. java 2 s . c om break; } } }
From source file:EntityReferenceTest.java
public static void main(String[] args) throws Exception { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); inputFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE); inputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE); XMLStreamReader reader = inputFactory.createXMLStreamReader(new FileInputStream("e.xml")); while (reader.hasNext()) { int event = reader.next(); if (event == XMLStreamConstants.CHARACTERS) System.out.println(reader.getText()); else if (event == XMLStreamConstants.ENTITY_REFERENCE) { System.out.println("en: " + reader.getLocalName()); System.out.println("er: " + reader.getText()); }// w w w . ja va 2 s . c o m } inputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE); reader = inputFactory.createXMLStreamReader(new FileInputStream("e.xml")); while (reader.hasNext()) { int event = reader.next(); if (event == XMLStreamConstants.CHARACTERS) System.out.println(reader.getText()); else if (event == XMLStreamConstants.ENTITY_REFERENCE) { System.out.println("en: " + reader.getLocalName()); System.out.println("er: " + reader.getText()); } } }
From source file:Main.java
public static void main(String[] args) throws Exception { XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader sr = factory.createXMLStreamReader(new FileReader("test.xml")); System.out.println(sr.getClass()); while (sr.hasNext()) { int eventType = sr.next(); if (eventType == XMLStreamReader.START_DOCUMENT) { continue; } else if (eventType == XMLStreamReader.END_ELEMENT) { System.out.println("End Element: " + sr.getLocalName()); } else if (eventType == XMLStreamReader.START_ELEMENT) { System.out.println("Start Element: " + sr.getLocalName()); }/* w w w .j a v a 2s. co m*/ } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { File file = new File("text.xml"); XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader reader = inputFactory.createXMLStreamReader(new FileInputStream(file)); int eventTypeID = reader.nextTag(); eventTypeID = reader.nextTag();// w ww . j av a 2 s.c o m eventTypeID = reader.next(); System.out.println("Hello " + reader.getText()); }
From source file:CursorApproachEventObject.java
public static void main(String[] args) throws Exception { String filename = "yourXML.xml"; XMLInputFactory xmlif = XMLInputFactory.newInstance(); xmlif.setEventAllocator(new XMLEventAllocatorImpl()); allocator = xmlif.getEventAllocator(); XMLStreamReader xmlr = xmlif.createXMLStreamReader(filename, new FileInputStream(filename)); int eventType = xmlr.getEventType(); while (xmlr.hasNext()) { eventType = xmlr.next(); if ((eventType == XMLStreamConstants.START_ELEMENT) && xmlr.getLocalName().equals("Book")) { StartElement event = getXMLEvent(xmlr).asStartElement(); System.out.println("EVENT: " + event.toString()); }/*from ww w.j a v a 2 s. com*/ } }