博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
dom4j 的小小测试
阅读量:6941 次
发布时间:2019-06-27

本文共 1271 字,大约阅读时间需要 4 分钟。

@Test	public void gogo() throws IOException{		InputStream in = this.getClass().getClassLoader()				.getResourceAsStream("content.html");		byte[] content = new byte[in.available()];		in.read(content);				Document document;		org.dom4j.Document document2;		InputStream inputStream = null;		try {			inputStream = new ByteArrayInputStream(content);			Tidy tidy = new Tidy();			init(tidy);			document = tidy.parseDOM(inputStream, null);			DOMReader domReader = new DOMReader();			document2 = domReader.read(document);			XPath path = DocumentHelper.createXPath("/html/body/table[3]/tbody/tr/td/table/tbody/tr/td/table/tbody/tr[2]/td/div[4]");  //xpath 路径			Node node  = path.selectSingleNode(document2);			System.out.println(node.getUniquePath());  //xpath			System.out.println(node.getNodeTypeName()); // Element			System.out.println(node.getName()); //div			System.out.println(node.asXML()); // 原始文本			System.out.println("kjl"+node.getText()); //null 			System.out.println(node.getStringValue()); //除去 标签			System.out.println(node.getPath()); // 不知道和 uniquepath 什么关系			System.out.println(node.getParent().asXML()); // 获取 dom 父节点		} finally {			Closeables.close(inputStream, false); // guava api 这个测试时完全可以不要,只是我在测试时刚好加了这个dependency		}	}

测试环境 maven guava dom4j,好像不能上传文件啊我,那就不上传了

转载地址:http://rsinl.baihongyu.com/

你可能感兴趣的文章
python3.5 的str类型和bytes类型的转换
查看>>
使用摄像头或视频运行 ORB-SLAM2 SLAM14讲 第一次课后作业
查看>>
Nginx源码剖析之内存池,与内存管理
查看>>
优化网站设计系列文章总结和导读
查看>>
列数组Program perl 数据结构
查看>>
位域简介
查看>>
用CALayer实现聚光灯效果
查看>>
Atitit。sql2016标准化的规划方案 v3 q2a
查看>>
在Windows .NET平台下使用Memcached
查看>>
Webpack 入门指南 - 2.模块
查看>>
C++ STL中Map的按Key排序
查看>>
【转载】Redis的一些使用场景
查看>>
【转】CString与string、char*的区别和转换
查看>>
英语词汇(3)Call out to sb
查看>>
spring自己主动装配Bean属性
查看>>
面对苦难请勇敢
查看>>
安全加固总论
查看>>
消息中间件概述
查看>>
008_线上排障汇总
查看>>
HRMS(人力资源管理系统)-从单机应用到SaaS应用-架构分析(功能性、非功能性、关键约束)-下篇...
查看>>