Solved

Javascript/XML DOM

Posted on 2001-07-18
2
331 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

627 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