Trouble with documentElement.getElementsByTagName

J

JJA

Here is my entire XML file - simplified to one node for testing:

<root>
<FlasConustbl>
<ID>42101</ID>
<AWARD>P015B030001</AWARD>
<INSTITUTION_KEY>300</INSTITUTION_KEY>
<INSTITUTION>Boston University</INSTITUTION>
<WORLDAREA>Africa</WORLDAREA>
<STREET>270 Bay State Road</STREET>
<CITY>Boston</CITY>
<STATE>Massachusetts</STATE>
<ZIP>02215</ZIP>
<COUNT>1</COUNT>
<PO_NAME>BOSTON</PO_NAME>
<NAMETYPE>POST OFFICE</NAMETYPE>
<ZIP_TYPE>NON-UNIQUE ZIP</ZIP_TYPE>
<Longitude>-71.101984</Longitude>
<Latitude>42.346498</Latitude>
<STATE_FIPS>25</STATE_FIPS>
<STATE_ABBR>MA</STATE_ABBR>
</FlasConustbl>
</root>

Here is my code:

var request = GXmlHttp.create();
request.open("GET", "SimpleOneNode.xml", true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
var xmlDoc = request.responseXML;
// obtain the array of markers and loop through it
var markers =
xmlDoc.documentElement.getElementsByTagName("FlasConustbl");

for (var i = 0; i < markers.length; i++) {
// obtain the attributes of each marker
var lat =
parseFloat(GXml.value(markers.getElementsByTagName("Latitude")));
var lng =
parseFloat(GXml.value(markers.getElementsByTagName("Longitude")));
var point = new GLatLng(lat,lng);
}
}
}
request.send(null);

The statement:

var markers =
xmlDoc.documentElement.getElementsByTagName("FlasConustbl")

....seems to create a valid array but then subsequent attempts to
retrieve elements by tagname return ""

Can you see what I am doing wrong?
 
M

Martin Honnen

JJA wrote:

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

for (var i = 0; i < markers.length; i++) {
// obtain the attributes of each marker
var lat =
parseFloat(GXml.value(markers.getElementsByTagName("Latitude")));


getElementsByTagName("Latitude") gives you a node list which can have
length 0 or 1 or greater, depending on how many elements with the tag
name are being found. I have no idea what GXml or GXml.value is or does
so I can't tell whether it makes sense to pass a node list to
GXml.value. If that function does not want a node list but a single node
then you could try
GXml.value(markers.getElementsByTagName("Latitude")[0])
 
J

JJA

Thank you so much. It did want a single node. Adding [0] did the trick.
I need to bone up on all this DOM stuff and parsing XML. Your help
moves me further along. I'll keep studying.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top