JAVA xml转dom_如何在Java中将String转换为DOMSource?
我需要一些幫助.在我的String filedata變量中,我存儲了一個
XMLdocument.現在我想將此變量轉換為DOMSource類型并使用此代碼:
DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = db.parse( new InputSource( new StringReader( filedata ) ) );
DOMSource source = new DOMSource(doc);
并通過javax.xml.transform.Transformer進行轉換:
Transformer transformer = XMLTransformerFactory.getTransformer(messageType);
StreamResult res = new StreamResult(flatXML);
transformer.transform(source,res);
但我的flatXML在轉換后是空的.我檢查了我的doc變量,它包含我的XML文檔并解析了所有內容.如果我將我的源代碼更改為真實路徑,一切正常并且工作正常:
Source source = new StreamSource("c:\\temp\\log\\SMKFFcompleteProductionPlan.xml");
我認為我的問題位于這行代碼中:
DOMSource source = new DOMSource(doc);
但我不知道如何解決這個問題.
總結
以上是生活随笔為你收集整理的JAVA xml转dom_如何在Java中将String转换为DOMSource?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 无约束优化算法——牛顿法与拟牛顿法(DF
- 下一篇: OpenMP基本概念