Resty项目地址在git下找一下应该能找的到。
Resty支持text, XML, JSON, binary。使用非常方便,官网有非常详细的使用说明。
为了给大家一个感性的认识,下面给一个XML的实例,且解决了中文乱码问题:
Resty r = new Resty();
NodeList nl=r.xml("http://218.22.67.142:8080/geoserver/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=wuhu:shuili_hanzhadoumen&maxFeatures=5").get("FeatureCollection/featureMember/shuili_hanzhadoumen/name");
for (int i = 0, len = nl.getLength(); i < len; i++) {
Node node=(Node)nl.item(i);
System.out.println(new String(node.getTextContent().getBytes("ISO-8859-1"),"GBK"));
}
输出结果:
双摆渡闸站
犁头尖站(闸)
王村站闸
保顺站闸
XML代码:
<wfs:FeatureCollection xmlns="http://www.opengis.net/wfs" xmlns:wfs="http://www.opengis.net/wfs" xmlns:wuhu="www.wuhu.cn" xmlns:gml="http://www.opengis.net/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="www.wuhu.cn http://218.22.67.142:8080/geoserver/wfs?service=WFS&version=1.0.0&request=DescribeFeatureType&typeName=wuhu%3Ashuili_hanzhadoumen http://www.opengis.net/wfs http://218.22.67.142:8080/geoserver/schemas/wfs/1.0.0/WFS-basic.xsd">
<gml:boundedBy>
<gml:null>unknown</gml:null>
</gml:boundedBy>
<gml:featureMember>
<wuhu:shuili_hanzhadoumen fid="shuili_hanzhadoumen.1">
<wuhu:the_geom>
<gml:Point srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
<gml:coordinates xmlns:gml="http://www.opengis.net/gml" decimal="." cs="," ts=" ">118.347698,31.358407</gml:coordinates>
</gml:Point>
</wuhu:the_geom>
<wuhu:LAYER>Unknown Point Feature</wuhu:LAYER>
<wuhu:id>0</wuhu:id>
<wuhu:name/>
<wuhu:type>0</wuhu:type>
<wuhu:flag>0</wuhu:flag>
</wuhu:shuili_hanzhadoumen>
</gml:featureMember>
<gml:featureMember>
<wuhu:shuili_hanzhadoumen fid="shuili_hanzhadoumen.2">
<wuhu:the_geom>
<gml:Point srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
<gml:coordinates xmlns:gml="http://www.opengis.net/gml" decimal="." cs="," ts=" ">118.416961,31.546034</gml:coordinates>
</gml:Point>
</wuhu:the_geom>
<wuhu:LAYER>Unknown Point Feature</wuhu:LAYER>
<wuhu:id>0</wuhu:id>
<wuhu:name>双摆渡闸站</wuhu:name>
<wuhu:type>0</wuhu:type>
<wuhu:flag>0</wuhu:flag>
</wuhu:shuili_hanzhadoumen>
</gml:featureMember>
<gml:featureMember>
<wuhu:shuili_hanzhadoumen fid="shuili_hanzhadoumen.3">
<wuhu:the_geom>
<gml:Point srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
<gml:coordinates xmlns:gml="http://www.opengis.net/gml" decimal="." cs="," ts=" ">118.381909,31.510878</gml:coordinates>
</gml:Point>
</wuhu:the_geom>
<wuhu:LAYER>Unknown Point Feature</wuhu:LAYER>
<wuhu:id>0</wuhu:id>
<wuhu:name>犁头尖站(闸)</wuhu:name>
<wuhu:type>0</wuhu:type>
<wuhu:flag>0</wuhu:flag>
</wuhu:shuili_hanzhadoumen>
</gml:featureMember>
<gml:featureMember>
<wuhu:shuili_hanzhadoumen fid="shuili_hanzhadoumen.4">
<wuhu:the_geom>
<gml:Point srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
<gml:coordinates xmlns:gml="http://www.opengis.net/gml" decimal="." cs="," ts=" ">118.39178,31.499681</gml:coordinates>
</gml:Point>
</wuhu:the_geom>
<wuhu:LAYER>Unknown Point Feature</wuhu:LAYER>
<wuhu:id>0</wuhu:id>
<wuhu:name>王村站闸</wuhu:name>
<wuhu:type>0</wuhu:type>
<wuhu:flag>0</wuhu:flag>
</wuhu:shuili_hanzhadoumen>
</gml:featureMember>
<gml:featureMember>
<wuhu:shuili_hanzhadoumen fid="shuili_hanzhadoumen.5">
<wuhu:the_geom>
<gml:Point srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
<gml:coordinates xmlns:gml="http://www.opengis.net/gml" decimal="." cs="," ts=" ">118.400652,31.499075</gml:coordinates>
</gml:Point>
</wuhu:the_geom>
<wuhu:LAYER>Unknown Point Feature</wuhu:LAYER>
<wuhu:id>0</wuhu:id>
<wuhu:name>保顺站闸</wuhu:name>
<wuhu:type>0</wuhu:type>
<wuhu:flag>0</wuhu:flag>
</wuhu:shuili_hanzhadoumen>
</gml:featureMember>
</wfs:FeatureCollection>