zoukankan      html  css  js  c++  java
  • Xpath 规格严格

     

     

    <?xml version = "1.0" encoding = "UTF-8"?>
    <persons>
            <country>china</country>
            <city>zhengzhou</city>
            <person>
                    <id>101</id>
                    <name>zhangsan</name>
                    <contacts>
                            <email>zhangsan@yahoo.cn</email>
                            <tel>0371-85555555</tel>
                            <qq>6683965</qq>
                    </contacts>
                    <addresses>
                            <address>
                                    <zipcode>450000</zipcode>
                                    <street>aaa</street>
                            </address>
                            <address>
                                    <zipcode>450001</zipcode>
                                    <street>bbb</street>
                            </address>
                    </addresses>
            </person>
            <person>
                    <id>102</id>
                    <name>lisi</name>
                    <contacts>
                            <email>lisi@yahoo.cn</email>
                            <tel>0371-68554545</tel>
                            <qq>224488</qq>
                    </contacts>
                    <addresses>
                            <address>
                                    <zipcode>450002</zipcode>
                                    <street>xxx</street>
                            </address>
                            <address>
                                    <zipcode>450003</zipcode>
                                    <street>yyy</street>
                            </address>
                    </addresses>
            </person>
    </persons>

     
    import java.io.File;
    import java.util.List;

    import org.dom4j.Document;
    import org.dom4j.Element;

    /**
    * XML相对路径测试
    *
    * @author leizhimin 2010-1-6 11:10:54
    */

    public class TestDom {

            public static void main(String[] args) {
                    File xmlf = new File("D:\\person.xml");
                    Document doc = XmlToolkit.makeDocument(xmlf, "UTF-8");

                    Element e_plan = (Element) doc.selectSingleNode("/persons");
                    Element e_id = (Element) e_plan.selectSingleNode("./country");
                    Element e_id1 = (Element) e_plan.selectSingleNode("country");
                    List<Element> eplist = e_plan.selectNodes("/persons/person");
                    for (Element ep : eplist) {
                            String path = ep.getPath();
                            Element id = (Element) ep.selectSingleNode("id");
                            System.out.println(id.getText());
                    }
                    System.out.println("---------------");

            }
    }
     
    101
    102
    ---------------

    Process finished with exit code 0
  • 相关阅读:
    Laravel 中使用 swoole 项目实战开发案例二 (后端主动分场景给界面推送消息)
    开发 Laravel 扩展的基本流程
    Swoole高效跟传统的web开发有什么区别?
    给各位PHP程序员十点未来的建议
    Swoole 是 PHP 中的 Node.js?
    Laravel 中使用 swoole 项目实战开发案例一 (建立 swoole 和前端通信)
    如何提高 PHP 代码的质量?第三:端到端 / 集成测试
    Java实现 LeetCode 811 子域名访问计数 (暴力)
    Java实现 LeetCode 810 黑板异或游戏 (分析)
    Java实现 LeetCode 810 黑板异或游戏 (分析)
  • 原文地址:https://www.cnblogs.com/diyunpeng/p/1872221.html
Copyright © 2011-2022 走看看