473,508 Members | 2,168 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trouble with documentElement.getElementsByTagName

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("FlasC onustbl");

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

The statement:

var markers =
xmlDoc.documentElement.getElementsByTagName("FlasC onustbl")

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

Can you see what I am doing wrong?

May 16 '06 #1
2 8648


JJA wrote:

var markers =
xmlDoc.documentElement.getElementsByTagName("FlasC onustbl");

for (var i = 0; i < markers.length; i++) {
// obtain the attributes of each marker
var lat =
parseFloat(GXml.value(markers[i].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[i].getElementsByTagName("Latitude")[0])
--

Martin Honnen
http://JavaScript.FAQTs.com/
May 16 '06 #2
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.

May 16 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1941
by: mr_burns | last post by:
Hi there, I am using the following function to import a xml file whether the users browser be IE or Mozilla: function importXML(file) { var xmlDoc; var moz = (typeof document.implementation...
3
1731
by: brian.newman | last post by:
I'm having trouble with XML in IE. I wrote the following function and it works fine in Firefox, but when I try to run it in IE, I get the error "getElementsByTagName(..).0' is null or not an...
1
2583
by: Max | last post by:
Hello everyone! i would want to know if the getElementsByTagName() function starts to find the elements from documentElement comprising the same documentElement. XML example: <?xml...
2
10615
by: ashish ranjan | last post by:
Hi there, I want to fetch data from database ,convert it in xml then send this xml from server.In Javascript file i am trying to parse it and bind these data to some control like textbox in...
13
1974
by: Saint48198 | last post by:
I'm having trouble with an array of data created using the 'getElementsByTagName' call. I'm trying to remove duplicates from the Array. code follows: // creates a list of all keywords and the...
1
10242
by: vunet | last post by:
The code below returns the viewport of the browser window but it does not work in IE7 because of the document.documentElement.clientHeight: function pageHeight(){ return window.innerHeight !=...
4
4513
by: agun | last post by:
Hello, Hi, i'm really a newbie in programming, especially javascript. I have one question in my mind right now. Sorry before if i'm not clear. Please see this example: ...
7
2454
by: kaiser0427 | last post by:
Ok, I have cleaned up the code and fixed some errors in it. The problem I am having is with the timer. If you uncomment the alert it pauses after every record. when I replace it with setInterval...
5
13304
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
0
7391
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7054
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5633
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5056
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4713
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1564
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
768
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
424
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.