xml解析-jaxp遍历结点
2024-08-30 05:03:58
jaxp遍历结点
把xml中所有的结点都打印出来
// 遍历结点把所有元素名称打印出来
/
1.创建解析器工厂
* 2.根据解析器工厂创建解析器
* 3.解析xml返回document
*
* 4.得到根节点
* 5.得到根节点的子节点
* 6.得到根节点子节点的子节点
* */
public static void listElement() throws Exception{
//创建解析器工厂
DocumentBuilderFactory builderFactoty = DocumentBuilderFactory.newInstance();
//创建解析器
DocumentBuilder builder = builderFactoty.newDocumentBuilder();
//解析xml返回document
Document document = builder.parse("src/person.xml");
//编写一个方法实现遍历操作
list1(document);
}
public static void list1(Node node)
{
if(node.getNodeType() == node.ELEMENT_NODE)
System.out.println(node.getNodeName());
//得到一层子节点
NodeList lists= node.getChildNodes();
for(int i=0;i!=lists.getLength();i++)
{
Node node1 = lists.item(i);
list1(node1);
}
}
最新文章
- 从0到1打造直播 App
- PHP 模拟 HTTP 摘要认证(Digest )
- [已解决] C3p0连接配置
- OAF_开发系列17_实现OAF数组应用Vector / Hashmap / Hashtable / Arraylist(案例)
- 一致性哈希算法以及其PHP实现
- 后缀数组 POJ 3693 Maximum repetition substring
- Xcode 报错信息
- 03-position和anchorPoint
- VS2012 常用web.config配置解析之自定义配置节点
- PPAS上运行pg_dump经过II
- bcp sqlcmd bulkinsert在unicode问题,Unexpected EOF encountered in BCP data-file
- vs2013 ADO联系SQL server2012数据库
- js漫谈
- MySQL in不走索引
- C setjmp和longjmp
- web---资源的下载及中文乱码问题
- .net基础学java系列(二)IDE
- 【APIO2018】铁人两项(圆方树,动态规划)
- Java开发面试题整理(2019春招)
- urllib处理包的简单使用
热门文章
- 即将是史上最全的meta大全
- Spring Boot 2.X(九):Spring MVC - 拦截器(Interceptor)
- ASP.NET MVC IOC依赖注入之Autofac系列(二)- WebForm当中应用
- Java集合专题
- session --中间件
- mysql 5.7版本安装
- STL--标准模板库--简要概述
- python中基本数据类型以及运算符
- 'Specifying a namespace in include() without providing an app_name '
- mac环境下Python虚拟环境的安装和配置