MyStAX.java
上传用户:zhaokuo188
上传日期:2022-05-16
资源大小:989k
文件大小:1k
源码类别:

xml/soap/webservice

开发平台:

Java

  1. package com.waytojob.xml;
  2. import java.io.FileInputStream;
  3. import java.io.FileNotFoundException;
  4. import javax.xml.stream.FactoryConfigurationError;
  5. import javax.xml.stream.XMLInputFactory;
  6. import javax.xml.stream.XMLStreamException;
  7. import javax.xml.stream.XMLStreamReader;
  8. public class MyStAX {
  9. /**
  10.  * @param args
  11.  */
  12. public static void main(String[] args) {
  13. try {
  14. XMLStreamReader xsr = XMLInputFactory
  15. .newInstance()
  16. .createXMLStreamReader(new FileInputStream("c:/dbinfo.xml"));
  17. xsr.next();
  18. xsr.next();
  19. xsr.next();
  20. while (xsr.hasNext()) {
  21. if (xsr.next() == XMLStreamReader.START_ELEMENT) {
  22. System.out.println(xsr.getName() + "###="
  23. + xsr.getElementText());
  24. }
  25. }
  26. while (xsr.hasNext()) {
  27. System.out.println("@@@  " + xsr.next());
  28. }
  29. } catch (FileNotFoundException e) {
  30. e.printStackTrace();
  31. } catch (XMLStreamException e) {
  32. e.printStackTrace();
  33. } catch (FactoryConfigurationError e) {
  34. e.printStackTrace();
  35. }
  36. }
  37. }