将多个html文件合成一个,将多个xml文件合并为一个html表

我在一个具有相同结构的目录中有很多XML,我需要生成HTML表,其中每个XML的“结果”都是一列。在我有一个csv文件之前,这很容易。但现在我甚至不知道如何开始。我读了一些关于XSLT的内容,但是我不知道如何使用它,因为我只有路径到XML文件的目录,而不是一个文件的路径。将多个xml文件合并为一个html表

例file1.xml

aa

ok

例file2.xml

aa

failed

我需要一个像这样的表:

filename | status1 | status2 | status n

aaa | ok | not ok | n

编辑:一些老片的代码由我的团队的人(原谅我的任何丑陋线的这种遗留代码,这是以前写了很多的时间)

public class Main {

private static ArrayList errors = new ArrayList();

private static int errorNum = 1;

public static void main(String[] args) throws JAXBException, IOException {

ArrayList tests = new ArrayList();

generateTestObjects(args, tests);

createHTML(tests, args[1]);

}

private static void generateTestObjects(String[] args, ArrayList arrayList) throws IOException{

Stream list = Files.list(Paths.get(args[0]));

list.forEach(arg0 -> {

try {

arrayList.add(unmarshall(arg0.toString()));

} catch (JAXBException e) {

e.printStackTrace();

}

});

list.close();

}

private static Test unmarshall(String fileName) throws JAXBException{

JAXBContext context = JAXBContext.newInstance(Test.class);

Unmarshaller un = context.createUnmarshaller();

Test test = (Test) un.unmarshal(new File(fileName));

return test;

}

private static void createHTML(ArrayList arraylist, String filename) throws IOException {

File file = new File("xunit.html");

FileWriter writer = new FileWriter(file);

writer.write("");

writer.write("");

writer.write("

");

writer.write("

Xunit Report");

writer.write("");

writer.write("");

writer.write("

");

writer.write("

Xunit Report

");

createHTMLTable(arraylist, writer);

createHTMLTableCSV(filename, writer);

writer.write("");

writer.write("");

writer.close();

}

private static void createHTMLTable(ArrayList arraylist, FileWriter fwriter) throws IOException{

fwriter.write("

fwriter.write("

");

fwriter.write("

Test case: ");

List testSections = arraylist.stream().map(Test::getTestSection).collect(Collectors.toList());

for(int file=0; file < arraylist.size(); file++){

fwriter.write("

" + arraylist.get(file).getAppInformation().getWorkstationId() + "");

}

for(int test=0; test < testSections.get(0).getTests().size(); test++){

fwriter.write("

");

String testName = testSections.get(0).getTests().get(test).getTestName();

testName = testName.replace("

testName = testName.replace(">", "&gt");

fwriter.write("

" + testName + "");

for(int file=0; file < arraylist.size(); file++){

String status = testSections.get(file).getTests().get(test).getStatus();

if(status.equalsIgnoreCase("PASSED")){

fwriter.write("

" + status + "");

} else{

fwriter.write("

" +" "+ status + "");

errorNum++;

}

}

fwriter.write("

");

}

fwriter.write("


");

for(Test test: arraylist){

int id = 1;

if(test.getTestSection().getFailedTests() != null){

for(int i=0;i

String testName = test.getTestSection().getFailedTests().get(i).getTestName();

testName = testName.replace("

testName = testName.replace(">", "&gt");

fwriter.write("

" + testName +" "+test.getAppInformation().getWorkstationId()+"
");

fwriter.write("

"+ test.getTestSection().getFailedTests().get(i).getDetails()+"
");

id++;

}

}

}

}

2017-08-08

arhu

+0

你可以看看XPath来查询xml节点(非常简单的API)并且构建html,StringBuilder就足够了。 –

+0

您可以使用Java来列出目录中的文件并[将您的xslt应用于每个文件](https://stackoverflow.com/questions/4604497/xslt-processing-with-java),同时输出到相同的输出文件中。 –

+1

在XSLT 2.0中,您可以使用'collection()'函数一次处理给定目录中的所有文件,并使用单个样式表。 –

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值