Click to See Complete Forum and Search --> : IXMLDOMNode and IXMLDOMAttribute question


owreese
January 16th, 2008, 11:40 AM
Development Environment:

Visual Studios 2005.
Windows XP, SP2

Problem:

I'm building an XML file from scratch. I have no problem creating the document, the processing instructions, adding nodes or even moving nodes around the document as it is being built. However, I can't seem to add a single attribute to anything within this document. Here I'm just trying to add information about a single item (it's an XML representation of a graph) and the code exists where I've indicated. What am I doing wrong or is there another way to do it?

bool ProjectOutfileXML::AddEdgeAttribute(GraphBasicEdge &edge)
{
CComVariant var;
IXMLDOMNodePtr child, grandchild;
IXMLDOMNodePtr attribute;

var.ClearToZero();
var.vt = VT_I4;
var.intVal = (short)NODE_ELEMENT;
if(FAILED(m_Xmldoc->createNode(var, node, NULL, &child)))
{
return false;
}
if(child == NULL)
{
return false;
}

if(FAILED(m_Edges->appendChild(child,&grandchild)))
{
return false;
}
if(grandchild == NULL)
{
return false;
}
else
{
grandchild.Release();
}

if(FAILED(m_Xmldoc->createAttribute(id,&attribute)))
{
return false;
}
if(attribute == NULL)
{
return false;
}

var.ClearToZero();
var.vt = VT_BSTR;
var.bstrVal = edge.m_EdgeID.Copy(); // m_EdgeID is a CComBSTR
if(FAILED(attribute->put_nodeValue(var)))
{
return false;
}

if(FAILED(child->appendChild(attribute,&grandchild)))
{
return false; // <-- This is where it winds up! What's wrong?
}