我尝试使用XMLLITE读写器更新XML文档NODE属性,但我无法做到。当我尝试添加新属性时,作者正在添加。
我的问题是 是否可以使用XMLLITE更新现有XML节点属性值?
<parent>
<child Name="AAA">Yes
</child>
</parent>
我想更新名称
的上述XML节点属性<parent>
<child Name="BBB">Yes
</child>
</parent>
XMLLIte c ++代码
//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;
}
}
我尝试按照你提到的那样做,我尝试设置属性的值,但是它没有设置现有属性的值,但是如果我尝试添加新属性,那么它添加属性。
当我试图循环直通节点列表时,节点类型永远不会出现在XmlNodeType_Attribute的情况下:我不确定为什么?
请给我你的建议,
由于 KARTHIK