<dependency> <groupId>com.fasterxml</groupId> <artifactId>aalto-xml</artifactId> <version>1.2.2</version> </dependency> <students> <student> <age>20</age> </student> <student> <age>22</age> </student> </students> import com.fasterxml.aalto.*; public class XMLParser { public static void main(String[] args) throws XMLStreamException, IOException { XMLInputFactory factory = new WstxInputFactory(); XMLStreamReader reader = factory.createXMLStreamReader(new FileInputStream("data.xml")); while (reader.hasNext()) { int eventType = reader.next(); if (eventType == XMLStreamConstants.START_ELEMENT) { if ("name".equals(reader.getLocalName())) { } else if ("age".equals(reader.getLocalName())) { } } } reader.close(); stream.close(); } }


上一篇:
下一篇:
切换中文