Reputation: 99
I'm trying to update a XML document NODE attributes using the XMLLITE reader and writer , but i couldn't. When i try to add new attribute then the writer is adding.
My Question is Is it possible to update the Existing XML Node attribute values using XMLLITE?
<parent>
<child Name="AAA">Yes
</child>
</parent>
I want to update the above XML Node Attribute of Name
<parent>
<child Name="BBB">Yes
</child>
</parent>
XMLLIte c++ Code
//if the element is price, then discount price by 25%
if (wcscmp(pQName, L"child") == 0)
{
inPrice = TRUE;
/*if (FAILED(hr = pWriter->WriteAttributeString(NULL, L"test", NULL, L"TEST")))
{
wprintf(L"Error writing WriteAttributeString, error is %08.8lx", hr);
return -1;
}*/
/*if (FAILED(hr = pWriter->WriteNodeShallow(pReader, FALSE)))
{
wprintf(L"Error writing WriteNodeShallow, error is %08.8lx", hr);
return -1;
}*/
//if (FAILED(hr = pReader->MoveToAttributeByName(L"Name", NULL)))
if (FAILED(hr = pReader->MoveToFirstAttribute()))
{
wprintf(L"Error Moving to Attribute, error is %08.8lx", hr);
}
LPCWSTR AttributeValue = NULL ;
if (FAILED(hr = pReader->GetValue(&AttributeValue, NULL)))
{
wprintf(L"Error Moving to Attribute, error is %08.8lx", hr);
}
if (FAILED(hr = pWriter->WriteNodeShallow(pReader, FALSE)))
{
wprintf(L"Error writing WriteNodeShallow, error is %08.8lx", hr);
return -1;
}
inPrice = TRUE;
if (FAILED(hr = pWriter->WriteAttributeString(NULL, L"Name", NULL, L"BBB")))
{
wprintf(L"Error writing WriteAttributeString, error is %08.8lx", hr);
return -1;
}
}
else
{
inPrice = FALSE;
if (FAILED(hr = pWriter->WriteNodeShallow(pReader, FALSE)))
{
wprintf(L"Error writing WriteNodeShallow, error is %08.8lx", hr);
return -1;
}
}
I tried doing that as you have mentioned, I tried to set the value of the attribute , but it not setting the value for the existing attribute , but if i tried to add a new attribute then its adding the attribute.
When i tried to loop the through node list , the node type never comes to the case XmlNodeType_Attribute: I 'M NOT SURE WHY?
Please give me your suggestions,
Thanks karthik
Upvotes: 0
Views: 348