Welcome to WebmasterWorld Guest from

Forum Moderators: httpwebwitch

Message Too Old, No Replies

read xml with javascript

xml file manipulation with javascript



7:20 am on Jun 2, 2008 (gmt 0)

5+ Year Member

Hi all,
I want to read the attributes (area and label) of this xml file using javascript.

<marker area="Melbourne1" label="burwood" />
<marker area="Melbourne4"label="cumming st" />
<marker area="Melbourne6" abel="illard" />

I tried to do it in couple of ways but it didn't work. I want to use this for google maps API.

var request = GXmlHttp.create();
request.open("GET", "test.xml", true);
request.onreadystatechange = function() {
if (request.readyState == 4) {

var xmlDoc = GXml.parse(request.responseText);
// obtain the array of markers and loop through it

var markers = xmlDoc.documentElement.getElementsByTagName("marker");

for (var i = 0; i < markers.length; i++) {
// obtain the attribues of each marker
var label = markers[i].getAttribute("label");
var area = markers[i].getAttribute("area");
// create the marker
var addresses = [label];



Appreciate your help guys
Thanks in advance.....


10:24 am on Jun 2, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Welcome to WebmasterWorld!

You may find these interesting:

W3School's Discussion of Browser-Side XML Parsers [w3schools.com]

XML for <script> [xmljs.sourceforge.net]


11:38 pm on Jun 2, 2008 (gmt 0)

5+ Year Member

thanks dude.. Is there a simple way to read all records (using Javascript) of an XML file (Attributes like area and label on above example) using a loop?
Because I just need to go through the records and save those attributes to a variable.

Thank You.


3:49 pm on Jun 3, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

I'd just read them in, using one of the methods above, then iterate through the object. I haven't done it that way myself, so I just have to think How I would do it.

I like to resolve XML at the server; not the client.


1:04 am on Jun 4, 2008 (gmt 0)

5+ Year Member

Thanks mate..btw I found it..doing it using a simple for loop and the values will store in to an array..

Thanks again


Featured Threads

Hot Threads This Week

Hot Threads This Month