使用 XmlLite IXmlWriter (C++) 在 prolog 中创建不带编码属性的 XML
Creating XML without encoding attribute in prolog using XmlLite IXmlWriter (C++)
我正在使用XmlLite库创建一个XML文件。我希望生成的 XML 文件的 prolog 不包含编码属性(仅包含版本):
<?xml version="1.0"?>
这是我的代码:
HRESULT hr = S_OK;
IStream *pOutFileStream = NULL;
IXmlWriter *pWriter = NULL;
CComPtr<IXmlWriterOutput> pWriterOutput;
//Open writeable output stream
if (FAILED(hr = SHCreateStreamOnFile(output_file_name, STGM_CREATE | STGM_WRITE, &pOutFileStream)))
{
wprintf(L"Error creating file writer, error is %08.8lx", hr);
HR(hr);
}
if (FAILED(hr = CreateXmlWriter(__uuidof(IXmlWriter), (void**) &pWriter, NULL)))
{
wprintf(L"Error creating xml writer, error is %08.8lx", hr);
HR(hr);
}
if(FAILED(CreateXmlWriterOutputWithEncodingName(pOutFileStream, NULL, L"UTF-8", &pWriterOutput))){
wprintf(L"Error setting xml encoding, error is %08.8lx", hr);
HR(hr);
}
if (FAILED(hr = pWriter->SetOutput(pWriterOutput)))
{
wprintf(L"Error, Method: SetOutput, error is %08.8lx", hr);
HR(hr);
}
if (FAILED(hr = pWriter->SetProperty(XmlWriterProperty_Indent, 4)))
{
wprintf(L"Error, Method: SetProperty XmlWriterProperty_Indent, error is %08.8lx", hr);
HR(hr);
}
if (FAILED(hr = pWriter->WriteStartDocument(XmlStandalone_Omit)))
{
wprintf(L"Error, Method: WriteStartDocument, error is %08.8lx", hr);
HR(hr);
}
我尝试删除对CreateXmlWriterOutputWithEncodingName()
的调用,但即便如此,还是会创建带有 UTF-8 的默认编码属性。我还尝试将NULL
作为该函数的第三个参数。
协助将不胜感激!
XML 声明由 WriteStartDocument
方法编写。
您可以使用 L"xml"
作为处理指令的名称来调用 WriteProcessingInstruction
,而不是调用 WriteStartDocument
,以所需的方式编写 XML 声明,例如:
if (FAILED(hr = pWriter->WriteProcessingInstruction(L"xml", L"version="1.0"")))
{
wprintf(L"Error, Method: WriteProcessingInstruction, error is %08.8lx", hr);
HR(hr);
}
这会将 XML 声明写入为 <?xml version="1.0"?>
。
相关文章:
- 如何创建一个CMake变量,除非显式重写,否则使用默认值
- 使用std::multimap迭代器创建std::list
- 在全局变量中保存类的实例以重新创建类(创建"backup")
- 如何确定我已使用非编码文件到达 EOF?
- 使用CMake创建QML插件
- 如何在c++中为模板函数实例创建快捷方式
- 在C++中,是否可以基于给定的标识符创建基类的新实例,反之亦然
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 如何从Intel MFT编码器的D11纹理创建IMFSample
- C++正在创建二进制搜索树:EXC_BAD_ACCESS错误.算法错误还是编码错误
- D3D11 创建着色器:编码的顶点着色器大小与指定大小不匹配
- 是否可以创建编码的动画壁纸
- 使用 XmlLite IXmlWriter (C++) 在 prolog 中创建不带编码属性的 XML
- 需要说明如何使用 C++ 在 Linux 上创建 utf-8 编码文件
- 如何从编码的 URL 创建 QUrl
- 如何使用编码的 AAC 数据手动创建 AVPacket 以发送 MPEGTS
- 使用opencv从帧创建divx编码的avi
- SNMP:无法创建/设置变量,编码错误
- 完全自定义Qt创建器编码风格
- 在哪里可以获得关于创建mpeg-1视频编码器的教程