将一段符合xml标准的string转换成xml文档中的element对象(使用dom4j)
只记录代码如下
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
private Element getElementFromString(String s) {
SAXReader builder = new SAXReader();
Document doc = null;
Element element=null;
try {
doc = builder.read(new StringReader(s));
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (doc!=null) {
element=doc.getRootElement();
}
return element;
}
SAXReader builder = new SAXReader();
Document doc = null;
Element element=null;
try {
doc = builder.read(new StringReader(s));
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (doc!=null) {
element=doc.getRootElement();
}
return element;
}