XML解析

需要dom4j-1.6.1.jar和jaxen-1.1.1.jars

涉及汉字乱码,请使用:


/**
     * 
     * Description: 将xml字符串转化为Document对象<br>
     * @param xml xml字符串
     * @return Document对象
     * @throws UnsupportedEncodingException
     * @throws DocumentException 
     * @see
     */
    public static Document stringToDocument(String xml)
        throws UnsupportedEncodingException, DocumentException
    {
        SAXReader reader = new SAXReader();
        ByteArrayInputStream is = new ByteArrayInputStream(xml.getBytes("UTF-8"));
        Reader r = new InputStreamReader(is, "UTF-8");
        Document document = reader.read(r);
        return document;
    }


你可能感兴趣的:(xml)