1
我正在使用Java中的簡單XML解析器。我一直使用很多源成功使用DocumentBuilderFactory,但我的新增功能之一是單個節點的集合。具有多個父節點的DocumentBuilderFactory
的file.xml看起來是這樣的:
<XML Version....>
<!DOCTYPE...>
<main_document_node>
.....others....
</main_document_node>
<XML Version....>
<!DOCTYPE...>
<main_document_node>
.....others....
</main_document_node>
我一直在使用這樣的命令:
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
Document d = dbf.newDocumentBuilder().parse(/path/file.xml);
但是,這似乎並沒有與多個父節點工作。有沒有比編寫一個臨時工作文件更簡單的方法,我寫了一個main_document_node?這僞代碼將是
new Writer temp.xml
new Reader file.xml
while not at the end of file.xml
read/write first main_document_node to temp
parse temp.xml
我認爲應該有使用的DocumentBuilderFactory的的InputSource /流選擇的方式,但我不知道如何去這樣做。
謝謝!
感謝。工作很好。 – James 2012-08-12 01:05:43