把Node转换成String
请教
已有这样一个如下形状的org.w3c.dom.Node
<a>
<a1> a </a1>
<a2> b </a2>
</a>
怎么把它转换成字符串 " <a1> a </a1> <a2> b </a2> "
------解决方案--------------------public org.jdom.Element getRoot(String filename)
{
org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder();
org.jdom.Document doc = null;
Element root=null;
int flag = 0;
try {
doc = builder.build(new java.io.File(filename));
root = doc.getRootElement();
}
catch (Exception e) {
System.out.println(e);
}
return root;
}
public String getXmlStr(String filename)
{
org.jdom.Document doc = new org.jdom.Document(getRoot(filename));
org.jdom.output.XMLOutputter outputter = new org.jdom.output.XMLOutputter( " ",false, "GBK ");
String str=outputter.outputString(doc);
return str;
}
记得给分