List of usage examples for javax.xml.stream XMLInputFactory createXMLStreamReader
public abstract XMLStreamReader createXMLStreamReader(java.io.InputStream stream) throws XMLStreamException;
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:MainClass.java
public static void main(String[] args) throws Exception { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader reader = inputFactory.createXMLStreamReader(new FileInputStream(new File("test.xml"))); int eventTypeID = reader.nextTag(); reader.require(XMLStreamConstants.START_ELEMENT, null, "person"); eventTypeID = reader.nextTag();//from w ww . ja va 2 s . c o m try { reader.require(XMLStreamConstants.START_ELEMENT, null, "first_name"); } catch (XMLStreamException e) { System.out.println("Assertion failed. " + e.getMessage() + " at " + reader.getLocation().getLineNumber() + ":" + reader.getLocation().getColumnNumber()); } System.out.println(reader.getElementText()); }
From source file:Main.java
public static void main(String[] args) throws Exception { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader reader = inputFactory.createXMLStreamReader(new FileInputStream(new File("test.xml"))); System.out.println(countEvents(reader)); reader = inputFactory.createXMLStreamReader(new FileInputStream(new File("test.xml"))); StreamFilter filter = new ElementOnlyFilter(); reader = inputFactory.createFilteredReader(reader, filter); System.out.println(countEvents(reader)); }
From source file:StAXTest.java
public static void main(String[] args) throws Exception { String urlString;// w w w. j av a2 s . 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:FISTest.java
public static void main(String[] args) throws Exception { XMLInputFactory factory = XMLInputFactory.newInstance(); FileInputStream fis = new FileInputStream("c.xml"); XMLStreamReader reader = factory.createXMLStreamReader(fis); reader.close();/*from w w w .j a va 2s . co m*/ fis.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(Customer.class); XMLInputFactory xif = XMLInputFactory.newFactory(); XMLStreamReader xsr = xif.createXMLStreamReader(new StreamSource(new File("input.xml"))); Unmarshaller unmarshaller = jc.createUnmarshaller(); unmarshaller.setListener(new LocationListener(xsr)); Customer customer = (Customer) unmarshaller.unmarshal(xsr); }
From source file:Main.java
public static void main(String[] args) throws Exception { File file = new File("yourXML.xml"); FileInputStream inputStream = new FileInputStream(file); XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader reader = inputFactory.createXMLStreamReader(inputStream); System.out.println(reader.getVersion()); System.out.println(reader.isStandalone()); System.out.println(reader.standaloneSet()); System.out.println(reader.getEncoding()); System.out.println(reader.getCharacterEncodingScheme()); parseRestOfDocument(reader);//from w ww .ja v a 2 s. c o m }
From source file:Main.java
public static void main(String[] args) throws Exception { JAXBContext context = JAXBContext.newInstance(User.class); XMLInputFactory xif = XMLInputFactory.newInstance(); FileInputStream fis = new FileInputStream("input.xml"); XMLStreamReader xsr = xif.createXMLStreamReader(fis); xsr.nextTag();//from www . j a va 2 s .c o m String noNamespaceSchemaLocation = xsr.getAttributeValue(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "noNamespaceSchemaLocation"); System.out.println(noNamespaceSchemaLocation); Unmarshaller um = context.createUnmarshaller(); User response = (User) um.unmarshal(xsr); }
From source file:Main.java
public static void main(String[] args) throws Exception { XMLInputFactory xif = XMLInputFactory.newFactory(); StreamSource xmlSource = new StreamSource("src/forum19559825/input.xml"); XMLStreamReader xsr = xif.createXMLStreamReader(xmlSource); positionXMLStreamReaderAtAnyElement(xsr); processAnyElement(xsr);/*from w w w. j a v a 2 s. co m*/ }