Welcome to WebmasterWorld Guest from

Forum Moderators: httpwebwitch

Message Too Old, No Replies

How to access xml attributes using Javascript?



3:28 pm on Mar 28, 2005 (gmt 0)

10+ Year Member

I am trying to access the values of attributes in my XML document with Javascript, here is an example of my XML file:

<User id="EEB5604C" name="C: SPaget">
<Email Value="spaget@mediageneral.com"/>

Please let me know if you have any ideas...



5:51 pm on Mar 28, 2005 (gmt 0)

10+ Year Member

You will need to use the DOM for attributes. Try the following syntax:

document.getElementByTagname(TAG NAME IN QUOTES).attributes.getNamedItem(ATTRIBUTE NAME IN QUOTES).value;

I know its a pain with the DOM, but it works for me.

For example:
For XML <person name="Bruce">, your javascript would be:


I tried it on my machine and it works :)



6:46 pm on Mar 28, 2005 (gmt 0)

10+ Year Member

Could you send me your sample file?

Here is what I have:

<script type="text/javascript" for="window" event="onload">
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")


XML File (note2.xml):
<person name="Todd" />

I am just trying to get the name to display in the webpage, any help would be greatly appreciated, thanks again for your help.


Featured Threads

Hot Threads This Week

Hot Threads This Month