import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.apache.commons.io.IOUtils;
import org.dom4j.Node;
import org.doom4j.DocumentHelper;
//文件流InputStream 轉Document,轉Element
public Element parseXml(InputStream stream){
SAXReader reader=new SAXReader();
Document document;
try {
document = reader.read(stream);
Element root=document.getRootElement();//Element爲根結點
return root;
} catch (DocumentException e) {
throw new RuleException(e);
}
}
//文件流InputStream 轉 XMl格式文件
String xml = IOUtils.toString(inputStream,"utf-8");
//Document 轉 InputStream
InputStream stream = IOUtils.toInputStream(document.asXML())
//Document 直接根據Element解析
Document doc = new Document();//
List<Element> oldEls = doc.getRootElement().elements();//得到Element集合後進行其餘操做
//Document轉 Xml格式文件
Document doc = new Document();//實際狀況 doc可根據其餘方式得到
String xml = doc.asXML();
//Xml 轉Document對象Document doc = DocumentHelper.parseText(xml);//Elemnt 轉XMlElement element ;Document doc = element.getDocument();String xml = doc.asXML();