I must first state that I am not a champion in programming, although created a handy website using html, php, MySQL and some javascript. Clearly, JS is by far the language I am almost using as a baby !
I have a set of data in a xml file with the following structure (sorry for the bad characters encoding) :
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<markers>
<marker lat="50.84310" lng="4.39330" name="7.7cm Sockel Flak 16 RheinMetall" category="FlakKanonen" nation="Allemagne" typecanon="Artillerie de DCA" lieu="Bruxelles - Musée Royal de l'Armée" pays="Belgique" url="../AfficheCanonGET.php?IdCanonAffiche=170" />
<marker lat="43.13810" lng="-80.26170" name="15cm sFH 13 L/14" category="SchwerenKanonen" nation="Allemagne" typecanon="Artillerie lourde" lieu="Brantford (ON) - Monument" pays="Canada" url="../AfficheCanonGET.php?IdCanonAffiche=256" />
<marker lat="61.00500" lng="24.45780" name="10cm K 14" category="LeichtKanonen" nation="Allemagne" typecanon="Artillerie légère" lieu="Hameenlinna - Finnish Artillery Museum" pays="Finlande" url="../AfficheCanonGET.php?IdCanonAffiche=317" />
<marker lat="45.88740" lng="11.04740" name="7cm M 99 GebK" category="GebirgsKanonen" nation="Autriche-Hongrie" typecanon="Artillerie de montagne" lieu="Rovereto - Museo Storico Italiano della Guerra" pays="Italie" url="../AfficheCanonGET.php?IdCanonAffiche=733" /><marker lat="-35.21550" lng="149.14510" name="13cm K 09 L/35" category="SchwerenKanonen" nation="Allemagne" typecanon="Artillerie lourde" lieu=" Mitchell, ACT - AWM reserve" pays="Australie" url="../AfficheCanonGET.php?IdCanonAffiche=1519" />
</markers>
This xml file is used in a javascript code for placing markers on a GoogleMap. Well it used to since the code does not work anymore since GoogleMap migrated to APIV3, without portability of the xml importing function I was using.
I managed to rewrite the map code in the new API v3 language, but I am stuck in what is probably very simple for you : Despite reading tens of similar threads, I am unable to adapt a code in javascript to transfer these xml file data in a javascript array
Here is what I am hoping to create :
marqueurCanonTest4[0] = {
latitudeCanon: "-34.94570",
longitudeCanon: "138.58050",
nomCanon: "7.7cm FK 16",
categorieCanon: "LeichtKanonen",
nationCanon: "Allemagne",
typeCanon: "Artillerie légère",
lieuCanon: "Adelaide, SA - Keswick Barracks, Army Museum of South Australia",
paysCanon: "Australie",
url: "../AfficheCanonGET.php?IdCanonAffiche=1"
};
marqueurCanonTest4[1] = {
latitudeCanon: "-36.14640",
longitudeCanon: "146.91680",
nomCanon: "7.7cm FK 16",
categorieCanon: "LeichtKanonen",
nationCanon: "Turquie",
typeCanon: "Artillerie légère",
lieuCanon: "Bandiana, VIC - Army Museum",
paysCanon: "Australie",
url: "../AfficheCanonGET.php?IdCanonAffiche=2"
};
etc …
I have tried to use XMLHttpRequest
, but probably incorrectly.
What are ways of achieving my goal?
3
Answers
If I understood your problem correctly, you need to create a markers array in JavaScript from the provided XML file.
You’ll need to parse the XML content and extract the necessary data. You can achieve this using the browser’s DOMParser to convert the XML string into a DOM object and then traverse the nodes to extract the marker information.
Here’s an example of how you can do this:
Using Powershell
Results
+ + + explanation in progress + + +