Search code examples
jqueryxmlgeoserver

xml root node attribute using jquery


I have geoserver response :

<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"/>

I would like to get numberOfFeatures.

I have tired below solution but does not work

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

Here is my fiddle: http://jsfiddle.net/uftmnggw/


Solution

  • Try this selector

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

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