473,396 Members | 2,024 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,396 software developers and data experts.

AJAX simple problem!

107 100+
hi, i think im missing something here....

i have some xml stored in javascript:

<picture>
<date>5-5-2007</date>
<title>Picture title</title>
<filename>filename.jpg</filename>
<size>6x4</size>
</picture>

i have stored "picture"

Expand|Select|Wrap|Line Numbers
  1. var XMLinfo = xmlDoc.getElementsByTagName('picture');
  2.  
all i then want to do, is list the childnode names and each of their values, this is what ive done so far:


Expand|Select|Wrap|Line Numbers
  1. var n = XMLinfo.childNodes.length;
  2. var output = "";
  3.  
  4.     for (i=0;i<n;i++)
  5.     {            
  6.        if (infoName != "#text" && infoName != "")
  7.        {
  8.         output += XMLinfo.childNodes[i].nodeName;
  9.         output += ": ";
  10.  
  11.                  //this is the line with the problem
  12.         output += XMLinfo.childNodes.item(i).nodeValue;
  13.        }
  14.  
  15.       }
  16.      alert(output);
  17.  

It shows the node names but Ive tried all sorts of combinations of syntax for the second line but cant get it to show the value.

Also tried:

Expand|Select|Wrap|Line Numbers
  1. infoName = XMLinfo.childNodes[i].nodeName;  XMLinfo.getElementsByTagName(infoName)[0].childNodes[0].nodeValue
  2.  
but that didnt work either. I know i could getElementByTagName() for each child node, but some "picture" nodes have a different number of childnodes so wanted to do it automatically.

Anybody see where i am going wrong?

thanks!

Andy
Jul 13 '07 #1
4 1354
jkmyoung
2,057 Expert 2GB
Do either of these work?
output += XMLinfo.childNodes[i].nodeValue;
output += XMLinfo.childNodes[i].childeNodes[0].nodeValue;
Jul 13 '07 #2
theS70RM
107 100+
Do either of these work?
output += XMLinfo.childNodes[i].nodeValue;
output += XMLinfo.childNodes[i].childeNodes[0].nodeValue;


nope afraid not:

first one returns null
second one gives and error and returns nothing

i don't understand, i seem to have tried every combination!
Jul 13 '07 #3
jkmyoung
2,057 Expert 2GB
output += XMLinfo.childNodes[i].childNodes[0].nodeValue;

I spelled child wrong. Yeah, not sure why it's not working then, if you can get the name, but not the children nodes of it.
Jul 13 '07 #4
theS70RM
107 100+
output += XMLinfo.childNodes[i].childNodes[0].nodeValue;

I spelled child wrong. Yeah, not sure why it's not working then, if you can get the name, but not the children nodes of it.

yea clocked the spelling mistake cheers.

what i dont understand is that when i use:

XMLinfo.getElementsByTagName('title')[0].childNodes[0].nodeValue

it returns the title no problem so i know the xml is ok. just cant see the other way of accessing this node other than using getElementsByTagName()
Jul 13 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

31
by: Tony | last post by:
I just noticed that prototype.js is one of the files in the Ajax.NET distribution - I'm pretty concerned about this. Does anyone know if this is the same "prototype.js" that is not well-liked...
5
by: Martin | last post by:
Hello NG, I've been doing some AJAX for a few weeks now. The basics worked fine so far, but now I've got the following problem which I can't solve: With AJAX you typically update/replace only...
1
by: www.web20developers.com | last post by:
http://www.web20developers.com http://www.web20developers.com/index.php?option=com_content&task=view... Ajallerix : AJAX, simple, fast Web image gallery demo ; at Novell AJAX -...
10
by: celoftis | last post by:
Using VS 2005: This morning, following the instructions here: http://ajax.asp.net/docs/overview/InstallingASPNETAJAX.aspx, I installed ASP.NET AJAX on my WinXP Pro development machine. Following...
17
by: Arjen | last post by:
Hi, I want to reload 2 divs at one click. Ive tried: <a href = "javascript:void(0);"...
6
by: =?Utf-8?B?U2hhd24gU2VzbmE=?= | last post by:
Greetings! I was researching AJAX to provide a solution to displaying status messages while a long process executed. I found several examples online and was able to use their code to get a quick...
0
by: Tarik Monem | last post by:
I have been working on an all AJAX/DOM web site which is set to go live today and I thought I'd share my discoveries with all of you whom have helped me when I have encountered different issues along...
10
by: Daniel Loose | last post by:
hi dear folks, i'm new to ajax. simple request no problem - but it seems when I set the response handler function, I can only pass the function name and not give parameters, so I have a problem...
11
by: burtonfigg | last post by:
I've read this article: http://www.oracle.com/technology/pub/articles/oracle_php_cookbook/ullman-ajax.html And from reading it thought it'd be interesting to try a bit of Ajax on my site. ...
4
by: sheldonlg | last post by:
I haven't received an answer with my other post, so I am rephrasing it here. In php I have a 2D array which I "print". The headers force it to be a file on the user's system. The user receives...
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...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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
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...

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.