0
我試圖從DOM對象中將格式化的XML文檔輸出爲字符串,如下面的代碼所示。事情是,雖然dom-> get_xml()方法確實返回一個值,但MXXMLWriter->輸出沒有,正如您在截圖中看到的那樣。所有的方法調用都返回S_OK。這裏可能是什麼問題?使用MXXMLWriter將XML文檔輸出爲字符串
這裏是我的代碼:
CComPtr<IMXWriter> w;
HRESULT hr;
hr = w.CoCreateInstance(__uuidof(MXXMLWriter), NULL, CLSCTX_INPROC_SERVER);
hr = w->put_indent(VARIANT_TRUE);
CComPtr<ISAXXMLReader> rd;
hr = rd.CoCreateInstance(__uuidof(SAXXMLReader60), NULL, CLSCTX_INPROC_SERVER);
CComPtr<ISAXContentHandler> hc;
hr = w.QueryInterface<ISAXContentHandler>(&hc);
CComPtr<ISAXErrorHandler> he;
hr = w.QueryInterface<ISAXErrorHandler>(&he);
CComPtr<ISAXDTDHandler> hd;
hr = w.QueryInterface<ISAXDTDHandler>(&hd);
hr = rd->putContentHandler(hc);
hr = rd->putErrorHandler(he);
hr = rd->putDTDHandler(hd);
hr = rd->putProperty(L"http://xml.org/sax/properties/lexical-handler", CComVariant(w));
hr = rd->putProperty(L"http://xml.org/sax/properties/declaration-handler", CComVariant(w));
BSTR body = ::SysAllocStringLen(NULL, 1024);
ZeroMemory(body, 1024 * sizeof(OLECHAR));
CComVariant out(body);
w->put_encoding(CComBSTR(L"utf-8"));
hr = w->put_output(out);
hr = rd->parse(CComVariant(dom));
dom->get_xml(&xmlStr);
return std::wstring(xmlStr);
你能詳細說明一下嗎?我有同樣的問題,但我沒有得到哪個對象需要「使用空字符串來指示作家」 – stu
@stu:你提供了一個變量,其中有一個空字符串的變量。如果此文檔摘錄無幫助,請開始一個新問題並提供不起作用的代碼段。 –
我會放棄,謝謝你回到我身邊。 – stu