我需要一些帮助。在我的 String
类型的 filedata 变量中,我保存了一个 XML 文档。现在我想将这个变量转换为 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);
但我不知道如何解决这个问题。