我需要一些帮助.在我的Stringfiledata变量中,我存储了一个XMLdocument.现在我想将此变量转换为DOMSource类型并使用此代码:
DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = db.parse( new InputSource( new StringReader( filedata ) ) );
DOMSource source = new DOMSource(doc);
Run Code Online (Sandbox Code Playgroud)
并通过javax.xml.transform.Transformer进行转换:
Transformer transformer = XMLTransformerFactory.getTransformer(messageType);
StreamResult res = new StreamResult(flatXML);
transformer.transform(source, res);
Run Code Online (Sandbox Code Playgroud)
但我的flatXML在转换后是空的.我检查了我的doc变量,它包含我的XML文档并解析了所有内容.如果我将我的源代码更改为真实路径,一切正常并且工作正常:
Source source = new StreamSource("c:\\temp\\log\\SMKFFcompleteProductionPlan.xml");
Run Code Online (Sandbox Code Playgroud)
我认为我的问题位于这行代码中:
DOMSource source = new DOMSource(doc);
Run Code Online (Sandbox Code Playgroud)
但我不知道如何解决这个问题.