Advertisement

05.16.2008 at 05:23AM PDT, ID: 23408011
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

parsing xml with javascript - breaks on hitting an empty node

Tags: javascript
hi,

i'm using javascript to loop through an xml file and pull out data according to the value of the ASP variable 'nameOfTerm'. the attached code works fine to pull out the required 'name' and 'definition' elements, UNTIL it comes across an empty 'definition' node, and then it ignores any names or definitons that come after the empty node.

e.g. if my xml file looks like this:

<term>
<name>1</name>
<definition>a</definition>
</term>

<term>
<name>2</name>
<definition>b</definition>
</term>

<term>
<name>3</name>
<definition></definition>
</term>

<term>
<name>4</name>
<definition>d</definition>
</term>

..and the variable nameOfTerm matches 1 or 2, everything works fine. but if it matches 3 or 4 i get no result. whereas if i put just a space in the 3rd definition node then they all work, but i don't want to have to do this.

does anyone have any ideas?

thanks,

liz
1:
2:
3:
4:
5:
6:
7:
8:
9:
//loop through them to find one with a name that matches the nameOfTerm
for (var i=0; i<noOfTerms; i++) { //for all the terms in the glossary
	name = xmlhttp.getElementsByTagName("glossary")[0].getElementsByTagName("term")[i].getElementsByTagName("name")[0].firstChild.nodeValue;
	definition = xmlhttp.getElementsByTagName("glossary")[0].getElementsByTagName("term")[i].getElementsByTagName("definition")[0].firstChild.nodeValue;
 
	if (name == '<%=nameOfTerm%>') { //if the name of the term passed into the glossary function matches a name in the glossary xml file
	document.write ("<a href='#' class='tooltip'><%=nameOfTerm%><span>" + definition.replace(/<(.|\n)+?>/gi, "") + "</span></a>");
	}//the above line uses a regex to remove all the html tags from the definition. gi means it does this globally and without case sensitivity
}
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: liz1976
Solution Provided By: mplungjan
Participating Experts: 1
Solution Grade: A
Views: 0
Translate:
Loading Advertisement...
05.16.2008 at 05:34AM PDT, ID: 21582089

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080236-EE-VQP-29 / EE_QW_2_20070628