XML
StAX
Create XMLStreamReader obje
Classes for creating an XMLStreamReader object
javax.xml.stream.XMLInputFactory javax.xml.stream.XMLStreamReader javax.xml.stream.XMLStreamException
Common methods of the XMLInputFactory class
Method | Description |
---|---|
newInstance() | A static method that returns an XMLInputFactory object. |
createXMLStreamReader(in) | Returns an XMLStreamReader object for the specified Reader or StreamInput object. This method throws an XMLStreamException. |
Code that creates an XMLStreamReader object
// create the XMLInputFactory object XMLInputFactory inputFactory = XMLInputFactory.newInstance(); try { // create a XMLStreamReader object FileReader fileReader = new FileReader("products.xml"); XMLStreamReader reader = inputFactory.createXMLStreamReader(fileReader); // Read XML here } catch (FileNotFoundException e) { e.printStackTrace(); } catch (XMLStreamException e) { e.printStackTrace(); }