none
MXXMLWriter手动生成XML文件时元素名为空 RRS feed

  • 问题

  • 我使用以下代码生成XML的时候,期望的结果是:<Books></Books>,但是返回的结果是:<></>,请问这是怎么回事?怎样做才能得到正确的结果?
    int _tmain(int argc, _TCHAR* argv[])
    {
    	::CoInitialize(NULL);
    	
    	MSXML2::IMXWriterPtr XMLWriter;
    	MSXML2::ISAXContentHandlerPtr handler;
    
    	HRESULT hr = XMLWriter.CreateInstance(__uuidof(MSXML2::MXHTMLWriter40));
    	CHECK_HR(hr);
    	
    	XMLWriter->put_indent(VARIANT_TRUE);
    	XMLWriter->put_byteOrderMark(VARIANT_TRUE);
    	XMLWriter->put_omitXMLDeclaration(VARIANT_FALSE);
    	XMLWriter->put_version(_bstr_t("1.0"));
    
    	handler = (ISAXContentHandlerPtr)XMLWriter;
    	//
    	
    	hr = handler->startDocument();
    	CHECK_HR(hr);
    	
    	hr = handler->startElement((unsigned short*)L"", 0, (unsigned short*)L"Books", 5, (unsigned short*)L"", 0, NULL);
    	CHECK_HR(hr);
    
    
    	hr = handler->endElement((unsigned short*)L"", 0, (unsigned short*)L"Books", 5, (unsigned short*)L"", 0);
    	CHECK_HR(hr);
    	
    	hr = handler->endDocument();
    	CHECK_HR(hr);
    	
    	_variant_t result;
    	hr = XMLWriter->get_output(&result);
    	CHECK_HR(hr);
    	
    	::CoUninitialize();
    	return 0;
    }
    2010年5月6日 7:02

答案