Advertisement

05.13.2008 at 08:05AM PDT, ID: 23398070
[x]
Attachment Details

removing html tags when parsing xml using javascript

Asked by liz1976 in Java Programming Language, JavaScript

Tags:

hi,

i have an xml file where a sample node might look like:

<definition>this is the text and it might have a &lt;a href="#link">link&lt;/a> in it and it might have some line breaks&lt;br />&lt;br /></definition>

i'm using the javascript snippet below to parse the xml and it works fine apart from one thing. i would like to get rid of all the html tags within the 'definition' nodes and be left with just the text. i.e. as if the xml file had just contained:

<definition>this is the text and it might have a link in it and it might have some line breaks</definition>

 i was wondering if anyone knows a simple way to do this?

would be grateful for any suggestions.

liz
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
<script type="text/javascript">
 
//call the included parseXML function above
parseXML("/inc/pla/glossary.xml");
 
//find out how many <term> tags in the glossary.xml file
noOfTerms = xmlhttp.getElementsByTagName("glossary")[0].getElementsByTagName("term").length;
 
//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 + "</span></a>");
	}
}
</script>
[+][-]05.13.2008 at 08:13AM PDT, ID: 21555845

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Java Programming Language, JavaScript
Tags: javascript
Sign Up Now!
Solution Provided By: Maverick_Cool
Participating Experts: 1
Solution Grade: B
 
 
[+][-]05.13.2008 at 09:01AM PDT, ID: 21556380

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.13.2008 at 09:09AM PDT, ID: 21556473

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628