通过访问ip返回结果(xml格式)

import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;




import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;


public class TestDomXml {


/**
* @param args
*/
public static void main(String[] args) {
URLConnection con = null;
URL url = null;
try{
//本地测试
// url = new URL("http://172.16.64.40:8080/vts/test.xml");http://10.35.18.56/PGIS_S_Address/Form?%E5%9C%B0%E5%9D%80=%E5%B4%87%E5%AE%81%E8%B7%AF&%E5%88%86%E7%B1%BB=
//真实
// url = new URL("http://10.35.18.56/PGIS_S_Address/Form?地址=崇宁路&分类=");
url = new URL("http://10.35.18.56/PGIS_S_Address/Form?%E5%9C%B0%E5%9D%80=%E5%B4%87%E5%AE%81%E8%B7%AF&%E5%88%86%E7%B1%BB=");
con = (URLConnection) url.openConnection();
// con.connect();
con.setDoInput(true);

       Document document = new SAXReader().read(con.getInputStream());  

/*List<Element> elements = document.getRootElement().element("匹配结果集合").elements();
List<Location> list = new ArrayList<Location>();
       for(Element e:elements){
        Location loca = new Location();
        loca.setDz(e.element("地址串").getText());
        loca.setFl(e.element("分类").getText());
        loca.setJd(e.element("X").getText());
        loca.setWd(e.element("Y").getText());
        list.add(loca);
       }*/

       Element element = document.getRootElement(); 
       System.out.println(element.asXML());
}catch(Exception e){
e.printStackTrace();
}
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值