完整的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