完整的XML文本我已阅读XML文件在Java中有这样的代码:得到节点实例
File file = new File("file.xml");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(file);
NodeList nodeLst = doc.getElementsByTagName("record");
for (int i = 0; i < nodeLst.getLength(); i++) {
Node node = nodeLst.item(i);
...
}
所以,我怎样才能从节点实例完整的XML内容? (包括所有标签,属性等)
谢谢。
你是什么意思 “得到充分的XML内容” 呢?你期待什么类型的对象回来?一个字符串?还有别的吗? –
完整的xml内容将在file.xml中,或者我缺少重点?否则请尝试http://stackoverflow.com/questions/35785/xml-serialization-in-java或http://xstream.codehaus.org/tutorial.html。 –
@PaulGrime,你的意思是,我必须用XML序列化器来序列化“节点”实例吗? – xVir