關于這個問題,我正試圖從 SO 周圍的 Java 專家那里獲得一些幫助。我在一個長期項目中遇到了 XMLSerializer 和 OutputFormat 的舊實現(xiàn)......我想知道是否有人可以指點該做什么,非常感謝您的意見......我嘗試了這種方法,但我無法用 LSSerializer 替換...問題...所以基本上有人在項目中使用了直接來自 IBM 內(nèi)部 JRE 的XMLSerializer 和 OutputFormat類......我怎樣才能將這種和平的代碼轉(zhuǎn)換為不受 WAS(Websphere Aplication Server)和使用 org.w3c 的依賴?...import org.apache.xml.serialize.OutputFormat;import org.apache.xml.serialize.XMLSerializer;import org.w3c.dom.DOMException;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.Node;import org.w3c.dom.NodeList;...public String toString() { StringWriter res = new StringWriter(); OutputFormat format = new OutputFormat(doc);//doc is type org.w3c.dom.Document format.setIndenting(true); XMLSerializer serializer = new XMLSerializer(res, format); try { serializer.serialize(doc); } catch (IOException e) { res.write(e.getMessage()); e.printStackTrace(); } return res.toString();}
1 回答

Helenr
TA貢獻1780條經(jīng)驗 獲得超4個贊
導入 org.w3c.dom.ls.* 并改用 LLSSerializer!您還需要創(chuàng)建一個 DOMImplementationLS 來調(diào)用,以便創(chuàng)建序列化程序。
添加回答
舉報
0/150
提交
取消