SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict AdRock952's Avatar
    Join Date
    Aug 2006
    Posts
    243
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    select specific record of xml file

    I am using Google maps and an xml file to create my maps.

    I read the xml file to get the info for the map but if my xml file has loads of records, it displays them all on the map.

    What I want to be able to do is select a specific record of the xml file.

    How would i select a record with a given id i choose?

    <?xml version="1.0" encoding="UTF-8" ?>
    Code XML:
    <markers>
    	<marker id="1" startaddress="Oxford Folk Festival" starttown="Oxford" startpostcode="OX1 9BE" startlat="51.729639" startlng="-1.28049" starttype="Start"></marker>
    </markers>
    Code JavaScript:
    GDownloadUrl("results.xml", function(data) {
    	var xml = GXml.parse(data);
    	var markers = xml.documentElement.getElementsByTagName("marker");
    	for (var i = 0; i < markers.length; i++) {
     
    		//Set up the start markers
    		var srtaddress = markers[i].getAttribute("startaddress");
    		var srttown = markers[i].getAttribute("starttown");
    		var srtpostcode = markers[i].getAttribute("startpostcode");
    		var srttype = markers[i].getAttribute("starttype");
    		var srtpoint = new GLatLng(parseFloat(markers[i].getAttribute("startlat")),
    								parseFloat(markers[i].getAttribute("startlng")));
    		var srtmarker = createStartMarker(srtpoint, srtaddress, srttown, srtpostcode, srttype);
    		var map = new GMap2(document.getElementById("map"));
    		map.addControl(new GSmallMapControl());
    		map.addControl(new GMapTypeControl());
    		map.setCenter(srtpoint,13);
    		map.addOverlay(srtmarker);
    	}
    });

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do a markers[i].getAttribute("id") and then compare to the desired value.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •