我有此代码:
void MyObj::Foo(IXMLDOMDocument* pDoc, BSTR bstrNodeName, CComBSTR &bstrNodeValue)
{
IXMLDOMNodeList *pIDOMNodeList = NULL;
IXMLDOMNode *pIDOMNode = NULL;
long nItems = 0;
HRESULT hr = S_OK;
try
{
pDoc->getElementsByTagName(bstrNodeName, &pIDOMNodeList);
pIDOMNodeList->get_length(&nItems);
pIDOMNodeList->reset();
pIDOMNodeList->get_item(0, &pIDOMNode);
pIDOMNode->get_text(&bstrNodeValue);
}
catch(...)
{
LOG("caught an exception in Foo\n");
throw "Failed";
}
LOG(“Exit Foo”)
}
使用L“ RqstUUID”呼叫Foo
XML:
<?xml version="1.0"?>
<SvcRes xmlns="MyRes">
<MyVer>1.0</MyVer>
<Svc>
<SvcParms>
<SvcID>MyTestId</SvcID>
<SvcVer>1.0</SvcVer>
<RqstUUID>00000001-2018-0110-1400-123456789123</RqstUUID>
</SvcParms>
</Svc>
</SvcRes>
运行代码时,在“ get_text”方法期间出现异常。 添加了更多打印的日志,其中“ nItems”值为0,这意味着我没有从“ getElementsByTagName”获得任何项目。 知道为什么我在pIDOMNodeList中没有收到任何项目吗?
谢谢