MSXML - how to change an attribute ?

Hi,

How can I set (change) an attribute within an XML file via MSXML ?

suppose the XML have an entry like:

<user>
<id name="aaa">
</id>
</user>


and I want to change the attribute value "name" from "aaa" to "bbb".
suppose I have the following code:

IXMLDOMNodePtr XPathParser::setSingleNode( std::string xPathExpression , std::string strNewVal)
{
MSXML::IXMLDOMNodePtr pNode = pXMLDoc_->selectSingleNode( xPathExpression.c_str() );
return pNode;
}

( So the call will be: selectSingleNodePtr("//user/id/@name") ,"bbb" )

How can I continue that code to do it ?

10X !
[723 byte] By [yaniv_av] at [2007-11-20 8:42:31]
# 1 Re: MSXML - how to change an attribute ?
How can I continue that code to do it ?
By using the IXMLDOMNode to get the IXMLDomElement pointer, and then calling setAttribute on it.

So, here is how one sets an attribute Id with a value of 2:
// You get a valid DOM Node pointer here...
MSXML::IXMLDOMNodePtr pNode = pXMLDoc_->selectSingleNode( xPathExpression.c_str() );

// QueryInterface it for IXMLDOMElement using CComQIPtr
CComQIPtr <IXMLDOMElement> pNodeElement (pNode);

// If QI succeeded, setAttribute
if (pNodeElement)
pNodeElement->setAttribute (CComBSTR (L"id"), CComVariant (2));
Siddhartha at 2007-11-9 13:30:33 >