Welcome to WebmasterWorld Guest from 50.19.0.90

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)

New User

5+ Year Member

joined:June 2, 2008
posts: 3
votes: 0


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

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

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

example:
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 June 2, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 21, 2005
posts: 1526
votes: 0


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 June 2, 2008 (gmt 0)

New User

5+ Year Member

joined:June 2, 2008
posts:3
votes: 0


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 June 3, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 21, 2005
posts: 1526
votes: 0


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 June 4, 2008 (gmt 0)

New User

5+ Year Member

joined:June 2, 2008
posts:3
votes: 0


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

Thanks again

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members