日期:2014-05-19 浏览次数:20819 次
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); Document doc = factory.newDocumentBuilder().parse(new InputSource(new StringReader(fragment)));
package com.ss; import java.io.StringReader; import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.io.SAXReader; public class Dom4jTest { public static void main(String[] args) { try { String xml = "<?xml version=\"1.0\" encoding=\"gb2312\"?><root></root>"; SAXReader reader = new SAXReader(); Document doc = reader.read(new StringReader(xml)); // 然后进行解析 } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }