MSXML4并设置编码字符串 [英] MSXML4 and setting the encoding string
问题描述
我使用MSXML4来生成XML。
I using MSXML4 to generate a XML.
我尝试将编码值设置为UTF-8。
I'm trying to set the encoding value to UTF-8.
这是我的代码:
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);
结果
总是 S_FALSE
,并且预处理字符串为:
result
is always S_FALSE
and the preprocessing string is:
<?xml version =1.0?& code>
<?xml version="1.0"?>
那么,为什么不显示编码字符串?
So, why isn't the encoding string showing up?
推荐答案
将xml保存到文件时,应该会看到<?xml version = 1.0encoding =UTF-8?>
声明。但是,根据此文章,当您使用 XML
属性的文档声明返回的不包含编码,这似乎是通过设计。这是你遇到的行为吗?文章指出:
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:
这是正常现象。它这样做的原因
是这样,你可以转身和
调用LoadXML与这个字符串,它
将工作。如果它不这样做,
LoadXML将失败,错误
消息:从当前编码
切换到不支持的指定编码。
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."
这篇关于MSXML4并设置编码字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!