1

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.

1 Answer 1

3

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?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.