开发者

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 simi开发者_如何转开发lar 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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜