Solved

Javascript/XML DOM

Posted on 2001-07-18
2
321 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

821 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