Java解析xml文件和html文件
来源:互联网 发布:c语言文件打开错误 编辑:程序博客网 时间:2024/06/07 12:34
1.解析XML文件
public void getXml() {try {String nameT="";File f = new File("C:\\Users\\dj\\Desktop\\test.xml");DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();DocumentBuilder builder = factory.newDocumentBuilder();Document doc = builder.parse(f);NodeList nl = doc.getElementsByTagName("entry");nameT = doc.getElementsByTagName("title").item(0).getFirstChild().getNodeValue();System.out.println(doc.getElementsByTagName("title").item(0).getFirstChild().getNodeValue());Workbook wb = new HSSFWorkbook();Sheet sheet11 = wb.createSheet(nameT);// 第一个sheet// 创建一行,在页sheet2上Row row = sheet11.createRow((short) 0);// 表头信息Cell cell0 = row.createCell(0);cell0.setCellValue("Job名称");Cell cell1 = row.createCell(1);cell1.setCellValue("最近执行时间");Cell cell2 = row.createCell(2);cell2.setCellValue("Case数");// Cell cell3 = row.createCell(3);// cell3.setCellValue("业务线");int rowrwonum = 1;for (int i = 0; i <= nl.getLength(); i++) {if (i == 0) {continue;}if (isContains(doc.getElementsByTagName("title").item(i).getFirstChild().getNodeValue())) {Row rowrow = sheet11.createRow(rowrwonum++);Cell row_c_1 = rowrow.createCell(0);row_c_1.setCellValue(doc.getElementsByTagName("title").item(i).getFirstChild().getNodeValue());Cell row_c_2 = rowrow.createCell(1);row_c_2.setCellValue(DateString2formatString(doc.getElementsByTagName("published").item(i - 1).getFirstChild().getNodeValue()));}// Cell row_c_3 = rowrow.createCell(3);// row_c_3.setCellValue(nameT);}FileOutputStream fileOut = new FileOutputStream("C:\\Users\\dj\\Desktop\\LastBuild.xls");// 把上面创建的工作簿输出到文件中System.out.println("结束了");wb.write(fileOut);// 关闭输出流fileOut.close();wb.close();} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}
2.解析html
public void testTest() {try {AutotestResultEntity autotestResultEntity=resultService.getRecordByParameter("test", "941").getData();org.jsoup.nodes.Document document = Jsoup.connect("http://jenkins.dj-inc.com/job/test/941/HTML_Report/overview.html").get();// String title = document.title();String text = document.text();// System.out.println(title);String s1 = text.substring(text.indexOf("总计 ") + 2, text.indexOf("报㝉"));String s2 = s1.replaceAll(" ", "##");// System.out.println(s2);String s3 = s2.substring(2, s2.lastIndexOf("##"));String s_1_3 = s3.substring(0, s3.indexOf("##"));int s_1 = Integer.valueOf(s_1_3);String s4 = s3.substring(s3.indexOf("##") + 2, s3.lastIndexOf("##"));String s_4_1 = s4.substring(0, s4.indexOf("##"));int s_2 = Integer.valueOf(s_4_1);String s5 = s4.substring(s4.indexOf("##") + 2, s4.length());int s_3 = Integer.valueOf(s5);//System.out.println(s_1 + "**" + s_2 + "" + s_3);autotestDsfResultEntity.setPassedCase(s_1);autotestDsfResultEntity.setSkippedCase(s_2);autotestDsfResultEntity.setFailedCase(s_3);resultService.updateRecordByParameter(autotestDsfResultEntity);// System.out.println(s1);} catch (NumberFormatException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}
阅读全文
0 0
- Java解析xml文件和html文件
- java 解析 xml文件
- java解析xml文件
- Java解析XML文件
- java解析xml文件
- java解析xml文件
- Java解析XML文件
- java解析xml文件
- java解析xml文件
- java解析xml文件
- java解析xml文件
- java解析XML文件
- java解析xml文件
- java解析xml文件
- Java 解析xml文件
- Java解析xml文件
- java解析xml文件
- Java XML文件解析
- 【Spring Cloud】--客户端负载均衡Spring Cloud Ribbon
- 一些帮助类:CommonUtils,,,,OkHttp3Util
- Springboot idea中实现热部署
- SpringMVC在Controller层中注入request的坑
- CSS-几种元素居中方式
- Java解析xml文件和html文件
- 有关C语言的知识---宏定义用法
- pandas读取csv编码问题
- win10 开启telnet服务
- 使用Java创建RESTful Web Service
- Visual Assist X_10.9.2238.2_Cracked
- cocos2d-x中DrawNode常见的图像绘制函数
- 18. PHP bcompiler
- ptam依赖