getElementsByTagName()
работает с DomDocument, но он не работает с DomDocument60
.getElementsBytagName не работает с DomDocument60
В приведенном ниже фрагменте getElementsByTagName(_bstr_t(".//author"), &xml2);
возвращает указатель NULL
в xml2.
Когда я перехожу из DomDocument60 в DomDocument, только тогда он работает. Мне нужно использовать DomDocument60 в моем проекте.
Любая идея, как эта проблема может быть исправлена, если я использую DomDocument60. Любая помощь приветствуется.
Ниже фрагмент кода:
#include "stdafx.h"
#import "msxml6.dll" raw_interfaces_only raw_native_types
using namespace MSXML2;
#include "stdlib.h"
#include "stdio.h"
#include <string>
#include <list>
using namespace std;
void LoadXML()
{
HRESULT hr1, hr;
hr1 = CoInitialize(NULL);
_variant_t vaNodeVal("c://Data.xml");
VARIANT var1 = vaNodeVal;
CComPtr<IXMLDOMDocument2> sSourceInputXml = 0;
hr = sSourceInputXml.CoCreateInstance(__uuidof(MSXML2::DOMDocument60));
if (hr == S_OK && sSourceInputXml != NULL)
{
VARIANT_BOOL isSuccessful = VARIANT_FALSE;
hr = sSourceInputXml->load(var1, &isSuccessful);
if(hr == S_OK && isSuccessful == VARIANT_TRUE)
{
CComQIPtr<MSXML2::IXMLDOMNodeList> xml2;
sSourceInputXml->getElementsByTagName(_bstr_t(".//author"), &xml2); //xml2 returned over here is NULL
long lCount = 0;
xml2->get_length(&lCount);
bool isPresent = false;
if (lCount == 0)
{
isPresent = false;
}
else
{
isPresent = true;
}
}
}
CoUninitialize();
}
data.xml используется:
<?xml version="1.0"?>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
<description>A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.</description>
</book>
<book id="bk103">
<author>Corets, Eva</author>
<title>Maeve Ascendant</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-11-17</publish_date>
<description>After the collapse of a nanotechnology
society in England, the young survivors lay the
foundation for a new society.</description>
</book>
</catalog>