Solved

Javascript/XML DOM

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

896 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

18 Experts available now in Live!

Get 1:1 Help Now