Solved

Javascript/XML DOM

Posted on 2001-07-18
2
324 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Title # Comments Views Activity
SharePoint and CAML query help 4 26
javascript delete path 7 44
Set css in function 11 54
How can I do this in Angular, instead of jQuery? 2 22
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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 basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to count occurrences of each item in an array.

734 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