Solved

Javascript/XML DOM

Posted on 2001-07-18
2
312 Views
Last Modified: 2013-11-19
I am very new to the XML arena and I am trying to figure out how to perform a certain task.  Any help is greatly apppreciated.  Here is the scenario.  I have an XML file and I have loaded it inside the DOM (javascript).  I would like to be able to loop through the DOM inside javascript and get certain attribute values.  This is what the xml looks like:

<data>
   <a fname='Joe' lname='Duke' email='joe@home.com'>
<b division='firstdivision'/>
<b division='seconddivision'/>
   </a>
   <a fname='Bob' lname='Smith' email='bob@home.com'>
<b division='thirddivision'/>
<b division='fourthdivision'/>
   </a>
</data>

I can currently get the first divsion by referencing the following:

myXML.selectSingleNode("Data/a/b/@division").text;

I would like to be able to loop through the DOM and grab all divisions from each element.  It doesn't matter how many divisions occur for each element.  The ultimate goal here is to check a checkbox or checkboxes for that particular division or divisions from the selected person(which will be fired from an onchange event for a drop down list).

If more information is required, please let me know.  Thanks in advance for the help.
0
Comment
Question by:mleopard
2 Comments
 
LVL 5

Accepted Solution

by:
mattyk earned 100 total points
ID: 6298421
Alright I think I knwo what you're after.  Take a look at the code sample below and let me know if this is it.

<script language="javascript">


 // Load XML
 var xml = new ActiveXObject("Microsoft.XMLDOM")
 xml.async = false
 xml.load("ee.xml")

 var allBs //this will be a collection of all the b tags
 var currDivision
 
 allBs = xml.getElementsByTagName("b")
 
 //Now we will loop through all of the divsions
 for(i=0;i<allBs.length;i++)
 {
      currDivision = allBs.item(i).attributes.getNamedItem("division").nodeValue
     alert(currDivision )
 }


</script>
0
 

Author Comment

by:mleopard
ID: 6298690
Good Answer, however, I got it working and it is very similar to your method. I will give you the points for your input. Thanks for the help.  
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now