List of usage examples for javax.xml.stream XMLInputFactory newInstance
public static XMLInputFactory newInstance() throws FactoryConfigurationError
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();// w w w. j a v a2 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 factory = XMLInputFactory.newInstance(); Reader fileReader = new StringReader(getXMLData()); XMLStreamReader reader = factory.createXMLStreamReader(fileReader); while (reader.hasNext()) { process(reader);/* w w w . j a va 2 s . c om*/ reader.next(); } }
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: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 w w w. j ava 2s .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 inputFactory = XMLInputFactory.newInstance(); inputFactory.setXMLResolver(new XMLResolver() { public Object resolveEntity(String publicID, String systemID, String baseURI, String namespace) throws XMLStreamException { System.out.println(systemID); return null; }/* ww w .j a va 2 s.c o m*/ }); XMLEventReader reader = inputFactory.createXMLEventReader(new FileInputStream("dtd.xml")); XMLEventWriter writer = XMLOutputFactory.newInstance().createXMLEventWriter(System.out); writer.add(reader); writer.flush(); }
From source file:Main.java
public static void main(String[] args) throws Exception { XMLInputFactory xif = XMLInputFactory.newInstance(); XMLEventReader xmlr = xif.createXMLEventReader((new FileInputStream(new File("./file.xml")))); boolean inline = false; StringBuffer sb = new StringBuffer(); while (xmlr.hasNext()) { XMLEvent event = xmlr.nextEvent(); if (event.isStartElement()) { StartElement element = (StartElement) event; if ("data".equals(element.getName().toString().trim())) { inline = true;/* www . ja v a2 s.c om*/ } } if (inline) { sb.append(xmlr.peek()); } if (event.isEndElement()) { EndElement element = (EndElement) event; if ("data".equals(element.getName().toString().trim())) { inline = false; System.out.println(sb.toString()); sb.setLength(0); } } } }
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 { XMLInputFactory xif = XMLInputFactory.newInstance(); XMLStreamReader xsr = xif.createXMLStreamReader(new FileReader("input.xml")); xsr.nextTag(); // Advance to statements element TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = tf.newTransformer(); while (xsr.nextTag() == XMLStreamConstants.START_ELEMENT) { File file = new File("out/" + xsr.getAttributeValue(null, "account") + ".xml"); t.transform(new StAXSource(xsr), new StreamResult(file)); }/*from www. j a v a2 s .c o m*/ }
From source file:Main.java
public static void main(String[] args) throws Exception { XMLInputFactory xif = XMLInputFactory.newInstance(); XMLStreamReader xsr = xif.createXMLStreamReader(new FileReader("input.xml")); xsr.nextTag(); // Advance to statements element while (xsr.nextTag() == XMLStreamConstants.START_ELEMENT) { TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = tf.newTransformer(); File file = new File("out" + xsr.getAttributeValue(null, "account") + ".xml"); t.transform(new StAXSource(xsr), new StreamResult(file)); }//from w ww.ja v a 2 s . com }
From source file:Main.java
public static void main(String[] args) throws Exception { XMLInputFactory xif = XMLInputFactory.newInstance(); XMLStreamReader xsr = xif.createXMLStreamReader(new FileReader("input.xml")); xsr.nextTag(); // Advance to statements element TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = tf.newTransformer(); while (xsr.nextTag() == XMLStreamConstants.START_ELEMENT) { DOMResult result = new DOMResult(); t.transform(new StAXSource(xsr), result); Node domNode = result.getNode(); }// w ww . j a v a 2 s. c om }