MyStAX.java
资源名称:xml001.rar [点击查看]
上传用户:zhaokuo188
上传日期:2022-05-16
资源大小:989k
文件大小:1k
源码类别:
xml/soap/webservice
开发平台:
Java
- package com.waytojob.xml;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import javax.xml.stream.FactoryConfigurationError;
- import javax.xml.stream.XMLInputFactory;
- import javax.xml.stream.XMLStreamException;
- import javax.xml.stream.XMLStreamReader;
- public class MyStAX {
- /**
- * @param args
- */
- public static void main(String[] args) {
- try {
- XMLStreamReader xsr = XMLInputFactory
- .newInstance()
- .createXMLStreamReader(new FileInputStream("c:/dbinfo.xml"));
- xsr.next();
- xsr.next();
- xsr.next();
- while (xsr.hasNext()) {
- if (xsr.next() == XMLStreamReader.START_ELEMENT) {
- System.out.println(xsr.getName() + "###="
- + xsr.getElementText());
- }
- }
- while (xsr.hasNext()) {
- System.out.println("@@@ " + xsr.next());
- }
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (XMLStreamException e) {
- e.printStackTrace();
- } catch (FactoryConfigurationError e) {
- e.printStackTrace();
- }
- }
- }