用JDK自带的JAXP解析XML,还需要别的开源包吗?
网上说JAXP1.1 中包含3个jar 文件,分别是JAXP.jar、crimson.jar 和 xalan.jar,需要下载这三个包吗?

解决方案 »

  1.   

    我想用JDK自带的,不用其他开源包,没做过XML解析,哪位高人指点一下?
      

  2.   

    不需要其他包了。JAXP的早期版本中,Sun包括JAXP API和一个叫做Crimson 的解析器。Crimson 是com.sun.xml软件包的一部分。
    在 JAXP 的新版本中 —— 包括在 JDK 中 —— Sun 已经重新包装了 Apache Xerces 解析器http://www.ibm.com/developerworks/cn/xml/x-jaxp/
    这文章写的不错。
      

  3.   

    org.w3c.dom.*
    javax.xml.parsers.*javax.xml.*jdk中的这些包 里面应该有你想要的东西! 本身就带这些 不用另外导入包
      

  4.   

    简单例子: DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    //support the namespace
    factory .setNamespaceAware(true);

    //Get the inputStream of your xml file
    FileInputStream in = new FileInputStream(new File("xxx.xml"));

    //Get the instance
    Document document = factory.newDocumentBuilder().parse(in); 

    //TODO your operation here
      

  5.   


    //You can also use the SaxParser

    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setNamespaceAware(true);
    //MyHandler is a class extends DefaultHandler  which use to handler the xml file
    factory.newSAXParser().parse(new File("xxx.xml"), new MyHandler());


    //There is also other parser for special xml files. For example :
    SOAPMessage  message = MessageFactory.newInstance().createMessage();
      

  6.   


    //The MessageFactory_Class in jdk1.6 is more powerful(support soap1.2) for soapmessage parse!