MSXML4 and setting the encoding string

≯℡__Kan透↙ 提交于 2019-12-25 01:06:45

问题


I using MSXML4 to generate a XML.

I'm trying to set the encoding value to UTF-8.

Here is my code:

const _bstr_t k_XML_Tag_Name ("xml");
const _bstr_t k_Processing_Tag_Name ("version=\"1.0\" encoding=\"utf-8\"");

MSXML2::IXMLDOMProcessingInstructionPtr pProccessingInstruction = m_pXmlDoc->createProcessingInstruction(k_XML_Tag_Name, k_Processing_Tag_Name);

HRESULT result = m_pXmlDoc->appendChild(pProccessingInstruction);

result is always S_FALSE and the preprocessing string is:

<?xml version="1.0"?>

So, why isn't the encoding string showing up?


回答1:


When you save the xml to a file you should see the <?xml version="1.0" encoding="UTF-8"?> declaration. However, according to this article, when you use the XML property of the document the declaration returned does not contain the encoding, which seems to be by design. Is this the behavior you are encountering? The article states that:

This is normal. The reason it did this is so that you can turn around and call LoadXML with this string and it will work. If it does not do this, LoadXML will fail with the error message: "Switch from current encoding to specified encoding not supported."



来源:https://stackoverflow.com/questions/3587474/msxml4-and-setting-the-encoding-string

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!