使用jquery的XML根节点属性



我有geoserver响应:

<wfs:FeatureCollection xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ogc="http://www.opengis.net/ogc" xmlns:tiger="http://www.census.gov" xmlns:topp="http://www.openplans.org/topp" xmlns:wfs="http://www.opengis.net/wfs" xmlns:ows="http://www.opengis.net/ows" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sf="http://www.openplans.org/spearfish" xmlns:gml="http://www.opengis.net/gml" xmlns:GIS="http://softwarekitchengisdata.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" numberOfFeatures="0" timeStamp="2015-09-20T12:15:46.527Z" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd"/>

我想要numberoffatures .

我已经厌倦了下面的解决方案,但不工作

xmlDoc = $.parseXML(data);
console.log(xmlDoc);
//tried this
console.log($(xmlDoc).filter(":first"));
//tried this
$(xmlDoc).find('wfs\:FeatureCollection').attr('numberOfFeatures');

这是我的小提琴:http://jsfiddle.net/uftmnggw/

试试这个选择器

$($doc).find("*").eq(0).attr('numberOfFeatures')

JsFiddle http://jsfiddle.net/uftmnggw/2/

最新更新