How to parse xml with namespaces using JQuery (and working for all browser .. )?



I need to parse an XML response from a web service using JQuery



http://ift.tt/1dW8QIk


Here you are a sample of my XML



<?xml version='1.0' encoding="ISO-8859-1" ?>
<wfs:FeatureCollection
xmlns:ms="http://ift.tt/1tE1RuH"
xmlns:wfs="http://ift.tt/1m4nTUG"
xmlns:gml="http://ift.tt/WaETtx"
xmlns:ogc="http://ift.tt/KDbkOK"
xmlns:xsi="http://ift.tt/ra1lAU"
xsi:schemaLocation="http://ift.tt/1m4nTUG http://ift.tt/1tE1RuO
http://ift.tt/1tE1RuH http://ift.tt/1tE1RuT">
<gml:boundedBy>
<gml:Box srsName="EPSG:4326">
<gml:coordinates>7.700007,44.802147 7.749396,44.849996</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<gml:featureMember>
<ms:IN.NUMERICIVICI.2012 fid="IN.NUMERICIVICI.2012.2728384">

<gml:boundedBy>
<gml:Box srsName="EPSG:4326">
<gml:coordinates>7.735138,44.810267 7.735138,44.810267</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<ms:boundary>
<gml:Point srsName="EPSG:4326">
<gml:coordinates>7.735138,44.810267</gml:coordinates>

</gml:Point>
</ms:boundary>
<ms:id>13800026457291</ms:id>
<ms:nome>Borgata Tetti Sotto</ms:nome>
<ms:civico>16</ms:civico>
<ms:istat>01004041</ms:istat>
<ms:cap>12030</ms:cap>

<ms:comune>CARAMAGNA PIEMONTE</ms:comune>
<ms:nome_ted> </ms:nome_ted>
<ms:provincia>CUNEO</ms:provincia>
<ms:regione>PIEMONTE</ms:regione>
</ms:IN.NUMERICIVICI.2012>
</gml:featureMember>
<gml:featureMember>

<ms:IN.NUMERICIVICI.2012 fid="IN.NUMERICIVICI.2012.2736621">
<gml:boundedBy>
<gml:Box srsName="EPSG:4326">
<gml:coordinates>7.735397,44.812403 7.735397,44.812403</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<ms:boundary>
<gml:Point srsName="EPSG:4326">

<gml:coordinates>7.735397,44.812403</gml:coordinates>
</gml:Point>
</ms:boundary>
<ms:id>13800026457290</ms:id>
<ms:nome>Borgata Tetti Sotto</ms:nome>
<ms:civico>25</ms:civico>
<ms:istat>01004041</ms:istat>

<ms:cap>12030</ms:cap>
<ms:comune>CARAMAGNA PIEMONTE</ms:comune>
<ms:nome_ted> </ms:nome_ted>
<ms:provincia>CUNEO</ms:provincia>
<ms:regione>PIEMONTE</ms:regione>
</ms:IN.NUMERICIVICI.2012>

</gml:featureMember>


I have to extract in some js variables these fields:



  • ms:nome

  • ms:civico

  • ms:istat

  • ms:cap

  • ms:comune


I need also to be sure that my code works right on IE, Firefox and Chrome.


I've seen and tried several solutions that I've found here in SO but none work.


Any suggestion is very appreciated!


Thank you very much in advance!!


Cesare


No comments:

Post a Comment