当前位置:首页 > 云服务器 > 正文内容

Xpath 规格严格,香港云服务器哪里好

来源于网络1个月前 (06-09)云服务器0
香港256IP千兆站群服务器BGP专线240元起! 华为云香港物理机精品线路全面上线![特价] 企业级CN2 GIA双程专线高速回国 T3机房 香港美国韩国海外独立物理服务器特价热销中!

 

 

<?xml version = "1.0" encoding = "UTF-8"?>
<persons>
        <country>china</country>
        <city>zhengzhou</city>
        <person>
                <id>101</id>
                <name>zhangsan</name>
                <contacts>
                        <email>[email protected]</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>[email protected]</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

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://www.cnblogs.com/diyunpeng/p/1872221.html

宝塔服务器面板,一键全能部署及管理,送你3188元礼包,点我领取

扫描二维码推送至手机访问。

版权声明:文章来源于互联网公开页面遵守互联网分享协议,若涉及侵权请联系客服处理。

本文链接:https://www.idchg.com/info/266708/

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。