xml 根节点属性使用 jquery
xml root node attribute using jquery
我有地理服务器响应:
<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"/>
我想获取 numberOfFeatures。
我已经厌倦了下面的解决方案但不起作用
xmlDoc = $.parseXML(data);
console.log(xmlDoc);
//tried this
console.log($(xmlDoc).filter(":first"));
//tried this
$(xmlDoc).find('wfs\:FeatureCollection').attr('numberOfFeatures');
这是我的 fiddle:
http://jsfiddle.net/uftmnggw/
试试这个选择器
$($doc).find("*").eq(0).attr('numberOfFeatures')
JsFiddle http://jsfiddle.net/uftmnggw/2/
我有地理服务器响应:
<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"/>
我想获取 numberOfFeatures。
我已经厌倦了下面的解决方案但不起作用
xmlDoc = $.parseXML(data);
console.log(xmlDoc);
//tried this
console.log($(xmlDoc).filter(":first"));
//tried this
$(xmlDoc).find('wfs\:FeatureCollection').attr('numberOfFeatures');
这是我的 fiddle: http://jsfiddle.net/uftmnggw/
试试这个选择器
$($doc).find("*").eq(0).attr('numberOfFeatures')
JsFiddle http://jsfiddle.net/uftmnggw/2/