[OpenLayers-Users] Get the value of the element of an XML File

Arnaud Vandecasteele arnaud.sig at gmail.com
Thu Jul 15 10:56:53 EDT 2010


Hi all,

I'm trying to get the value of an XML file  from an external server.
Below are the steps I do.

1/ I download this XML file with a classic Ajax request :

var getVesselsXML = new OpenLayers.Ajax.Request(
urlVessels,
                                {
                                  method: 'get'
                                  ,onSuccess : drawVessels
                                  ,extractAttributes: true
                                }
                        );

The result of the request is :

"<POSITIONS>
<V_POS LAT="42.35675" LON="4.2338452" N="RED COUGAR" T="9" H="43"
S="53" F="ES" M="225350000" L="32" E="5" />
<V_POS LAT="42.532299" LON="4.35115" N="AQUAGLORY" T="7" H="217"
S="157" F="GR" M="240119000" L="289" E="2" />...
</POSITIONS>"

2/ In the drawVessels method I parse the result  :

var XmlFormat = new OpenLayers.Format.XML();
vessels = XmlFormat.read(XmlvesselsRequest.responseText);

But I don't know how to get the attributes of a specific node. For
example, how can i Get the LON and the LAT of each node ?

I already tried somethings like that but it return me an empty string :

vessel = XmlFormat.getElementsByTagNameNS(vessels,'*','V_POS');

for (i in vessel){
   var LAT = XmlFormat.getAttributeNS(vessel[i],'*','LAT');
   console.log(LAT);
}



Thanks for your help


Best Regards

Arnaud



More information about the Users mailing list