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?
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 theXML
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: