提前道歉 - 我知道这已经被问了一千次了,但我已经浏览了很多文章/文档,我真的很迷茫。
我有一个类,它接收一个 XML 文件,然后使用 DocumentBuilder 将其解析为一个新文件,该文件将用作其他类使用的源。
我需要测试我的方法(无效)。我的项目已经完成,但我需要测试。
如果有人能向我展示这将如何完成,我可以继续对我的其他类遵循相同的逻辑,因为我项目中 90% 的方法不返回任何内容。
谢谢...
public class XmlToCsv {
public static void xmlToCsv(String sourceXlsFile, String sourceCsvFile, String sourceXmlFile) throws Exception {
//define the files
File stylesheet = new File(sourceXlsFile);
File xmlSource = new File(sourceXmlFile);
//create the DocumentBuilder to parse the XML file
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(xmlSource);
//input the stylesheet to transform the XML to
StreamSource stylesource = new StreamSource(stylesheet);
Transformer transformer = TransformerFactory.newInstance().newTransformer(stylesource);
//write a new output file using the stylesheet format
Source source = new DOMSource(document);
Result outputTarget = new StreamResult(new File(sourceCsvFile));
transformer.transform(source, outputTarget);
}
}
慕桂英3389331
芜湖不芜
温温酱
相关分类