package xml;
import java.io.StringReader;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
public class ReadXmlDom4j {
public static void main(String[] args){
String xmlStr = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><rsp><user><buyer_credit><level>1</level><score>9</score><total_num>9</total_num><good_num>9</good_num></buyer_credit><nick><![CDATA[honda418]]></nick><sex><![CDATA[m]]></sex></user></rsp>";
StringReader read = new StringReader(xmlStr);
SAXReader reader = new SAXReader();
Document doc;
try {
doc = reader.read(read);
Element root = doc.getRootElement();
System.out.println(root.getName());
}catch(DocumentException e){
e.printStackTrace();
}
}
}
java解析xml字符串-dom4j
最新推荐文章于 2024-10-16 15:27:24 发布