MSXML Problems  
Author Message
David N.4117





PostPosted: XML and the .NET Framework, MSXML Problems Top

Hi All,

I am developing my company application using VS2003 C++ with Win32 SDK /ALT/STL. The application uses MSXML 6.0 to create/read/write XML document to/from XML file. I ran into two problems described below:

1. The application adds whitespace to the XML document so that if the XML document is opened with text editor such as Notepad, children node will be indented, making it easier for user to read the document. However, the weird thing is that the XML file is only indented with debug version. If the application is compiled with release mode, XML file is not indented (I am sure there is no #ifdef _DEBUG around the code block that adds whitespace to the document)

2. I cannot remove an attribute from a node. I tried both removeAttribute() and removeAttributeNode() methods, but none is working. Below is the code:

BSTR bstrName = SysAllocString(L"FSecure");

if(bstrName)

{

IXMLDOMAttribute* pAttrNode = NULL;

IXMLDOMAttribute* pAttrRemove = NULL;

// xmlNode->m_pDOMElement->removeAttribute(bstrName);

xmlNode->m_pDOMElement->getAttributeNode(bstrName,&pAttrNode);

if(pAttrNode)

{

xmlNode->m_pDOMElement->removeAttributeNode(pAttrNode,&pAttrRemove);

pAttrNode->Release();

}

SysFreeString(bstrName);

}

Any comments Thanks in advance.




.NET Development4  
 
 
Martin Honnen





PostPosted: XML and the .NET Framework, MSXML Problems Top

As for removeAttribute, I have no problems with MSXML 6 using that, a simple example (JScript) is as follows:

var xmlDocument = new ActiveXObject('Msxml2.DOMDocument.6.0');
xmlDocument.loadXML('<root fsecure="true"/>');
WScript.Echo(xmlDocument.documentElement.attributes.length);
WScript.Echo(xmlDocument.xml);
xmlDocument.documentElement.removeAttribute('fsecure');
WScript.Echo(xmlDocument.documentElement.attributes.length);
WScript.Echo(xmlDocument.xml);

When I run that the result is as expected:

1
<root fsecure="true"/>

0
<root/>

meaning the attribute is correctly removed. I can only assume that you have a DTD defining a default attribute value. In that case if you call removeAttribute then the removed attribute is directly replace with a new attribute with the default attribute value I think.