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);
        }
    }

最新文章

  1. 从0到1打造直播 App
  2. PHP 模拟 HTTP 摘要认证(Digest )
  3. [已解决] C3p0连接配置
  4. OAF_开发系列17_实现OAF数组应用Vector / Hashmap / Hashtable / Arraylist(案例)
  5. 一致性哈希算法以及其PHP实现
  6. 后缀数组 POJ 3693 Maximum repetition substring
  7. Xcode 报错信息
  8. 03-position和anchorPoint
  9. VS2012 常用web.config配置解析之自定义配置节点
  10. PPAS上运行pg_dump经过II
  11. bcp sqlcmd bulkinsert在unicode问题,Unexpected EOF encountered in BCP data-file
  12. vs2013 ADO联系SQL server2012数据库
  13. js漫谈
  14. MySQL in不走索引
  15. C setjmp和longjmp
  16. web---资源的下载及中文乱码问题
  17. .net基础学java系列(二)IDE
  18. 【APIO2018】铁人两项(圆方树,动态规划)
  19. Java开发面试题整理(2019春招)
  20. urllib处理包的简单使用

热门文章

  1. 即将是史上最全的meta大全
  2. Spring Boot 2.X(九):Spring MVC - 拦截器(Interceptor)
  3. ASP.NET MVC IOC依赖注入之Autofac系列(二)- WebForm当中应用
  4. Java集合专题
  5. session --中间件
  6. mysql 5.7版本安装
  7. STL--标准模板库--简要概述
  8. python中基本数据类型以及运算符
  9. 'Specifying a namespace in include() without providing an app_name '
  10. mac环境下Python虚拟环境的安装和配置