Solved

Writing a xml output with special character to a table

Posted on 2006-11-11
4
329 Views
Last Modified: 2007-12-19
In my xml node, i have a node value with special character < and >
<MarkText><ASSY MARK></MarkText>

I can retrieve it using alert(MarkTextNodes.item(i).text);
However, when i try to write the output to a table :

strMarkObjectTable += "<table><tr><td>" + MarkTextNodes.item(i).text + "</tr></td></table>";
output.innerHTML=strMarkObjectTable;

It is giving me an empty table. Please help!
0
Comment
Question by:sherly
[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
  • 2
4 Comments
 
LVL 16

Accepted Solution

by:
Peter Kwan earned 125 total points
ID: 17924139
You need to escape the < to &lt; and > to &gt; as the following:

strMarkObjectTable += "<table><tr><td>" + MarkTextNodes.item(i).text.replace("<", "&lt;").replace(">", "&gt;") + "</tr></td></table>";
0
 
LVL 2

Author Comment

by:sherly
ID: 17924166
is there an option to add in the check for "&" as well?
0
 
LVL 16

Expert Comment

by:Peter Kwan
ID: 17924179
Yes, you can replace & with &amp;. But remember to add as the first replace, otherwise, the < and > does not work.

What I mean is the following:

var x =  MarkTextNodes.item(i).text.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
0
 
LVL 2

Author Comment

by:sherly
ID: 17924183
Thank you so much!
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…
Suggested Courses

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