简体   繁体   中英

How to display entities taken from XML with Javascript?

There MUST be an easy way to do that! I didn't want to ask this question again if somebody already asked it but I couldn't find something similar in this site... anyway :

So I have a XML file :

<marker>This is a test &amp; it&#039;s fun. &eacute;</marker>

So when I read this XML file with Javascript, I want to put it in a text input of a form, but it comes out with the & amp; etc instead of :

This is a test & it's fun. é

I really don't understand why I'm having so much problem finding a way to show the text right... Don't we all have the same problem with XML??? Help me!! In PHP, this would be sooo easy :(

Thanks a bunch in advance

Your XML isn't well-formed, so you probably isn't reading it as xml but plain text

Through DOM, you'll get &amp; and &#039; correctly, but an error on &eacute; (undefined character entity)

EDIT

Since you don't have problems opening that file as XMLDOMDocument, you should be able to run following code into your browser. Make sute to create a SPAN tag to display that text:


var text = xmldoc.selectSingleNode("//marker").text;
document.getElementsByTagName("SPAN")[0].innerHTML = text;
alert(text);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM