MSXML and Whitespace
Hi,
I have problems inserting whitespace into my xml document. I have the
following code.
//init com for this thread
CoInitialize(NULL);
//create an instance of it
HRESULT hr = doc_ptr.CreateInstance(_uuidof(MSXML2:OMDocument60));
if (FAILED(hr))
{
MessageBeep(0);
CoUninitialize();
return;
}
doc_ptr->async = VARIANT_FALSE;
HRESULT res = doc_ptr->put_preserveWhiteSpace(TRUE);
//
MSXML2::IXMLDOMDocument3::createDocumentFragment();
///
MSXML2::IXMLDOMProcessingInstructionPtr pPI = NULL;
//doc_ptr->preserveWhiteSpace = TRUE;
pPI = doc_ptr->createProcessingInstruction
("xml", "version='1.0' encoding='UTF-8'");
_variant_t vNullVal;
vNullVal.vt = VT_NULL;
doc_ptr->insertBefore(pPI, vNullVal);
///
//Create document element.
MSXML2::IXMLDOMNodePtr pRootNode= NULL;
_variant_t varNodeType((short)MSXML2::NODE_ELEMENT);
//create a node, whos name should be the document element name
CString str;
str.LoadString(IDS_XML_DOC_ELEM);
pRootNode= doc_ptr->createNode(varNodeType,
((LPCTSTR)str),_T(""));
doc_ptr->appendChild(pRootNode);
//this part adds a node under neath the root with some text as its value but
the spacing gets cut off at the end.
MSXML2::IXMLDOMNodePtr temp;
temp = NULL;
str.LoadString(IDS_XML_NODE_NAME);
temp = doc_ptr->createNode(varNodeType,(LPCTSTR)str,_T(""));
temp->nodeTypedValue = _T("this is a test of spacing ");
pRootNode->appendChild(temp);
The problem is the white space is removed from the temp node.
any ideas please