如何解决如何使用正则表达式解析xml节点?
我来自ajax的xml响应是
<gml:Polygon srsName="http://www.opengis.net/gml/srs/epsg.xml#3857">
<gml:outerBoundaryIs>
<gml:LinearRing>
<gml:coordinates xmlns:gml="http://www.opengis.net/gml" decimal="." cs="," ts=" ">33.36,49.79 33.7410766436,49.788 33.17,49.09 33.62,49.16 33.07,49.46 33.36,49.79</gml:coordinates>
</gml:LinearRing>
</gml:outerBoundaryIs>
</gml:Polygon>
我想在<gml:coordinates>
节点中获取坐标。
我可以使用正则表达式或其他方法获取坐标值吗?
解决方法
var text = '<gml:Polygon srsName="http://www.opengis.net/gml/srs/epsg.xml#3857">'
+ '<gml:outerBoundaryIs>'
+ '<gml:LinearRing>'
+ '<gml:coordinates xmlns:gml="http://www.opengis.net/gml" decimal="." cs="," ts=" ">33.36,49.79 33.7410766436,49.788 33.17,49.09 33.62,49.16 33.07,49.46 33.36,49.79</gml:coordinates>'
+ '</gml:LinearRing>'
+ '</gml:outerBoundaryIs>'
+ '</gml:Polygon>';
// parse xml
var parser = new DOMParser();
var doc = parser.parseFromString(text,"text/xml");
// extract node using XPath
var node = doc.evaluate('//*[local-name()="coordinates"]',doc,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;
// get node text
console.log(node.textContent);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。