作为selenium的一部分,我们以xml的形式生成结果文件。 现在我们生成像“ReportManager.xml”这样的文件 在这个文件中,我们想在第二行添加一个xsl样式表链接,
以下是代码:Report Magaer.xml
int myValue = myListe.Max(t => t.Key);
现在我想要包含行
<?xml version="1.0" encoding="UTF-8"?>
<ReportManager><SmokeTest><Version DisplayName="ERP Build: ERP 9">
<Family DisplayName="Module">
<Product DisplayName="Branch Setup"/>
<Product DisplayName="Academics Module"/>
<Product DisplayName="Admission Process"/>
<Product DisplayName="Examination Settings"/>
<Product DisplayName="Examination Production"/>
<Product DisplayName="Delete Master Activity Remarks">
<Report ActualResult="Activity Deleted :etetettre is shown" Executed="Wed Jan 20 12:08:02 IST 2016" ExpectedResult="Activity Deleted :etetettre should be shown" Status="Pass" StepNumber="1"/>
<Report ActualResult="Activity Deleted :wfdreqfreqwreeeeeee is shown" Executed="Wed Jan 20 12:08:21 IST 2016" ExpectedResult="Activity Deleted :wfdreqfreqwreeeeeee should be shown" Status="Pass" StepNumber="1"/>
</Product>
</Family>
</Version>
</SmokeTest>
</ReportManager>
动态地在第二行,请让我知道如何在java中编写这个脚本。
答案 0 :(得分:0)
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
public class XMLTransformationEndingTag {
public static void main(String[] args) throws IOException, URISyntaxException, TransformerException {
String XMLFile="<path for your xml file>";
String XSLFile="<path for your xsl file>";
TransformerFactory fac = TransformerFactory.newInstance();
Source xslt= new StreamSource(new File(XSLFile));
Transformer trans = fac.newTransformer(xslt);
Source text=new StreamSource(new File(XMLFile));
trans.transform(text, new StreamResult(new File("file.xml")));
}
}