List of usage examples for javax.xml.stream XMLStreamReader getEventType
public int getEventType();
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();/*from w w w . jav a 2s . com*/ int 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();// ww w . jav a 2s. com if ((eventType == XMLStreamConstants.START_ELEMENT) && xmlr.getLocalName().equals("Book")) { StartElement event = getXMLEvent(xmlr).asStartElement(); System.out.println("EVENT: " + event.toString()); } } }
From source file:Main.java
public static void main(String[] args) throws Exception { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader("<a></a>")); reader = inputFactory.createFilteredReader(reader, new ElementOnlyFilter()); System.out.println(reader.getEventType()); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader reader = inputFactory.createXMLStreamReader(new FileInputStream(new File("l.xml"))); reader = inputFactory.createFilteredReader(reader, new ElementOnlyFilter()); System.out.println(reader.getEventType()); }
From source file:Main.java
public static void main(String[] args) throws Exception { String filename = "yourXML.xml"; XMLInputFactory xmlif = null; xmlif = XMLInputFactory.newInstance(); xmlif.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE); xmlif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE); xmlif.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE); xmlif.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE); System.out.println("FACTORY: " + xmlif); System.out.println("filename = " + filename); FileInputStream fis = new FileInputStream(filename); XMLStreamReader xmlr = xmlif.createFilteredReader(xmlif.createXMLStreamReader(fis), new Main()); int eventType = xmlr.getEventType(); printEventType(eventType);/* w ww.ja va 2s .c o m*/ while (xmlr.hasNext()) { eventType = xmlr.next(); printEventType(eventType); printName(xmlr, eventType); printText(xmlr); if (xmlr.isStartElement()) { printAttributes(xmlr); } printPIData(xmlr); } }
From source file:Main.java
public static void main(String[] args) throws Exception { String filename = "yourXML.xml"; XMLInputFactory xmlif = null; xmlif = XMLInputFactory.newInstance(); xmlif.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE); xmlif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE); xmlif.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE); xmlif.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE); System.out.println("FACTORY: " + xmlif); System.out.println("filename = " + filename); FileInputStream fis = new FileInputStream(filename); XMLStreamReader xmlr = xmlif.createFilteredReader(xmlif.createXMLStreamReader(fis), new MyFilter()); int eventType = xmlr.getEventType(); printEventType(eventType);/*w w w . j a va2 s. c o m*/ while (xmlr.hasNext()) { eventType = xmlr.next(); printEventType(eventType); printName(xmlr, eventType); printText(xmlr); if (xmlr.isStartElement()) { printAttributes(xmlr); } printPIData(xmlr); } }
From source file:MyStreamFilter.java
public static void main(String[] args) throws Exception { String filename = "yourXML.xml"; XMLInputFactory xmlif = null; xmlif = XMLInputFactory.newInstance(); xmlif.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE); xmlif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE); xmlif.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE); xmlif.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE); System.out.println("FACTORY: " + xmlif); System.out.println("filename = " + filename); FileInputStream fis = new FileInputStream(filename); XMLStreamReader xmlr = xmlif.createFilteredReader(xmlif.createXMLStreamReader(fis), new MyStreamFilter()); int eventType = xmlr.getEventType(); printEventType(eventType);/*ww w . j ava 2s. co m*/ while (xmlr.hasNext()) { eventType = xmlr.next(); printEventType(eventType); printName(xmlr, eventType); printText(xmlr); if (xmlr.isStartElement()) { printAttributes(xmlr); } printPIData(xmlr); } }
From source file:StaxCursorTest.java
public static void main(String[] args) throws Exception { String filename = "yourXML.xml"; XMLInputFactory xmlif = null; xmlif = XMLInputFactory.newInstance(); xmlif.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE); xmlif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE); xmlif.setProperty(XMLInputFactory.IS_COALESCING, Boolean.FALSE); try {//from w w w . ja va 2 s. c o m XMLStreamReader xmlr = xmlif.createXMLStreamReader(filename, new FileInputStream(filename)); int eventType = xmlr.getEventType(); printStartDocument(xmlr); while (xmlr.hasNext()) { eventType = xmlr.next(); printStartElement(xmlr); printEndElement(xmlr); printText(xmlr); printPIData(xmlr); printComment(xmlr); } } catch (XMLStreamException ex) { System.out.println(ex.getMessage()); if (ex.getNestedException() != null) { ex.getNestedException().printStackTrace(); } } }
From source file:Main.java
public static void printPIData(XMLStreamReader xmlr) { if (xmlr.getEventType() == XMLEvent.PROCESSING_INSTRUCTION) { System.out.print("<?" + xmlr.getPITarget() + " " + xmlr.getPIData() + "?>"); }//w ww . j a v a 2s .c o m }
From source file:Main.java
private static void process(XMLStreamReader reader) { int eventType = reader.getEventType(); switch (eventType) { case XMLStreamConstants.START_ELEMENT: System.out.println("Start element: " + reader.getLocalName()); int count = reader.getAttributeCount(); for (int i = 0; i < count; i++) { String name = reader.getAttributeLocalName(i); String value = reader.getAttributeValue(i); System.out.println("\tAttribute name/value: " + name + "/" + value); }/*from w ww.j a v a 2s .com*/ break; case XMLStreamConstants.END_ELEMENT: System.out.println("End element: " + reader.getLocalName()); break; case XMLStreamConstants.CHARACTERS: System.out.println("Text: " + reader.getText()); break; default: break; } }