将一段符合xml标准的string转换成xml文档中的element对象(使用dom4j)
时间:2011-02-23 来源:菜鸟学编程
代码
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;
}
相关阅读 更多 +