homepage Welcome to WebmasterWorld Guest from 54.204.90.135
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / XML Development
Forum Library, Charter, Moderators: httpwebwitch

XML Development Forum

    
read xml with javascript
xml file manipulation with javascript
thivankm




msg:3664618
 7:20 am on Jun 2, 2008 (gmt 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.....

 

cmarshall




msg:3664709
 10:24 am on Jun 2, 2008 (gmt 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]

thivankm




msg:3665344
 11:38 pm on Jun 2, 2008 (gmt 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.

cmarshall




msg:3665841
 3:49 pm on Jun 3, 2008 (gmt 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.

thivankm




msg:3666269
 1:04 am on Jun 4, 2008 (gmt 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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / XML Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved