Posted on 2009-10-25 18:43
leekiang 閱讀(445)
評論(0) 編輯 收藏 所屬分類:
文件處理
????String? xml="<?xml version=\"1.0\" encoding=\"GBK\" ?><root><test>0</test></root>";
?? 應該使用Document document = saxReader.read(new ByteArrayInputStream(xml.getBytes()));?
如果使用Document?? document?? =?? saxReader.read(xml);會報no protocol 異常
如果xml的encoding="utf-8",則xml.getBytes()要改為xml.getBytes("utf-8"),否則會報錯
Element root=??document.getRootElement();
得到root后取子元素,既可以
Element e=root.element("test");
也可以
for (Iterator it = root.elementIterator(); it.hasNext();) {
Element e = (Element) it.next();
??? String n = e.getName();
?? String v=e.getStringValue()
}
http://www.javatx.cn/clubPage.jsp?ccStyle=0&ccID=15&tID=1922http://lavasoft.blog.51cto.com/62575/66953