开发者

How to specify the encoding of an XML document using Javascript

Hello i am trying to create a开发者_运维知识库 document using Javascript and there's a problem with the encoding of the document, because reject all the non-ascii characters, the string that im passing is this "verificación" but is replaced with this "�", how i can fixed that.

This is my code:

function createDoc(string){
    if (window.DOMParser)
      {
        parser = new DOMParser();


        doc = parser.parseFromString('<?xml version="1.0" encoding="UTF-8"?>'+string, "text/xml");
      }
    else // Internet Explorer
      {
        doc = new ActiveXObject("Microsoft.XMLDOM");
        doc.async = "false";
        doc.loadXML('<?xml version="1.0" encoding="UTF-8"?>'+string);
      }

    return doc
}

Thanks in advance.


Javascript strings are all UTF-16-encoded. You could try specifying that.

Where does the string come from? Is the string correct before parsing it?

Also, when is it being displayed? What encoding is expected there?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜