473,399 Members | 3,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

XMLHttpRequest - how to get XML attributes

hello,

my ASP.NET page uses javascript to retrieve XML data from another ASPX
page. i do this like so (snippets for example):
var ajaxResults;
var xmlhttp = new XMLHttpRequest();

xmlhttp.open("GET", "getData.aspx", true);

xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4) //ready
{
if (xmlhttp.status == 200) //success
{
//alert('success');
var xml = xmlhttp.responseXML;

//return cross-browser DOM object
if (xml.documentElement)
ajaxResults = xml.documentElement;

} else {
//alert('There was a problem retrieving the data:\n' +
xmlhttp.statusText);
}
}
}

xmlhttp.send(null)
....which populates "ajaxResults". the data looks like:
<results timestamp="6/20/2008 11:34:33 AM">
<dataItem value="1">Call for Service</dataItem>
</results>
....cool. i can then use this in JS like so:
var ddlItems = document.getElementById("ddlItems");

var i;
for (i = 0; i < resultNodes.length; i++){

//add an item to list
ddlItems.options.length ++;
ddlItems.options[i].value = i; // ? how do i get the attribute of the
node?
ddlItems.options[i].text = resultNodes[i].firstChild.nodeValue; //
gets TEXT of "<dataItem>"
}
....all well and good (enough for me). but the question: how do i parse
the *attribute* values from my above returned XML object?
thanks,
matt
Jun 27 '08 #1
3 1346
On Jun 20, 11:38*am, SpaceMarine <spacemar...@mailinator.comwrote:
...all well and good (enough for me). but the question: how do i parse
the *attribute* values from my above returned XML object?
found something helpful:
http://msdn.microsoft.com/en-us/libr...78(VS.85).aspx

so in the above, heres how i can get the root node's timestamp
attribute:

alert(ajaxResults.attributes[0].value);

...now all i have to do is get the <dataItem>'s attribute. will post
syntax when located.

Jun 27 '08 #2
On Jun 20, 11:53*am, SpaceMarine <spacemar...@mailinator.comwrote:
so in the above, heres how i can get the root node's timestamp
attribute:

* *alert(ajaxResults.attributes[0].value);

...now all i have to do is get the <dataItem>'s attribute. will post
syntax when located.
found it:

//attribute value for result node
alert(resultNodes[i].attributes.getNamedItem("value").value);

sm
Jun 27 '08 #3


"SpaceMarine" <sp*********@mailinator.comwrote in message
news:d6**********************************@m73g2000 hsh.googlegroups.com...
On Jun 20, 11:53 am, SpaceMarine <spacemar...@mailinator.comwrote:
>so in the above, heres how i can get the root node's timestamp
attribute:

alert(ajaxResults.attributes[0].value);

...now all i have to do is get the <dataItem>'s attribute. will post
syntax when located.

found it:

//attribute value for result node
alert(resultNodes[i].attributes.getNamedItem("value").value);

sm
You should also be able to use the terser:

resultNodes[i].getAttribute("value")

--

Joe Fawcett (MVP - XML)
http://joe.fawcett.name

Jun 27 '08 #4

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

Similar topics

10
by: Matt Kruse | last post by:
I'm aware of the circular reference memory leak problem with IE/closures. I'm not sure exactly how to resolve it in this situation. Also, Firefox appears to grow its memory size with the same code....
22
by: googlegroups | last post by:
I am playing with the XMLHTTPRequest method to perform client/server transactions. I have it set up right now so that when readyState is 4, it takes the XML and processes it. This works great until...
8
by: Ian Collins | last post by:
Is there a way to do this in IE? In Firefox, one can simply append a node from an XML return to the current document. IE whinges about 'No such interface supported' -- Ian Collins.
9
by: Phil_Harvey | last post by:
I am redoing my website and trying to get it to do something more exciting using Javascript. I did normal Java at university and code at work in VB.NET. I have got reasonably far into what I want...
6
by: Nathan | last post by:
Can I run two XMLHTTPRequest objects at the same time? Im able to get one to work without problems. If I put a call to a function inside the first ones onreadystatechange function, the 2nd ones...
4
by: JP | last post by:
Hello, I am trying to figure out how can I read particular content of the page after I have requested page into XMLHttpRequest object. Is there a way to parse somehow responseText? In pseudo...
1
by: geevaa | last post by:
http://www.phpbuilder.com/columns/kassemi20050606.php3 XMLHttpRequest and AJAX for PHP programmers James Kassemi Introduction: Although the concept isn't entirely new, XMLHttpRequest...
1
by: Tarik Monem | last post by:
OK, I'm pretty sure this cannot work because I'm trying to use JavaScript (client-side) to write to an xml file (which is server-side) using XMLHttpRequest. Can I use PHP do what I'm trying to do?...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.