我需要找到將JDOM元素(及其所有定製節點)轉換爲Document
的更簡單高效的方法。 ownerDocument()
將不起作用,因爲這是JDOM 1
版本。在沒有DocumentBuilderFactory或DocumentBuilder的情況下將JDom 1.1.3元素轉換爲文檔
此外,org.jdom.IllegalAddException: The Content already has an existing parent "root"
使用下面的代碼時發生異常。
DocumentBuilderFactory dbFac = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFac.newDocumentBuilder();
Document doc = null;
Element elementInfo = getElementFromDB();
doc = new Document(elementInfo);
XMLOutputter xmlOutput = new XMLOutputter();
byte[] byteInfo= xmlOutput.outputString(elementInfo).getBytes("UTF-8");
String stringInfo = new String(byteInfo);
doc = dBuilder.parse(stringInfo);