lookus
2006-04-27 08:47:37 UTC
I'm a newer to xml. And i wanna to use msxml to read xml file.
here is my code
////// msxml_test.cpp
////// use MFC in a shared dll
#include <iostream>
#include <cmath>
#include <string>
#import <msxml4.dll>
#include <msxml.h>
using namespace std;
int main()
{
cout << "BEGIN" <<endl;
HRESULT hr;
long cnt;
try
{
hr = ::CoInitialize(NULL);
MSXML2::IXMLDOMDocumentPtr pDoc;
MSXML2::IXMLDOMNodeListPtr pNodeList;
MSXML2::IXMLDOMNodePtr pNode;
if(FAILED(hr))
throw "failed to com init";
hr = pDoc.CreateInstance(__uuidof(MSXML2::DOMDocument40));
if(FAILED(hr))
throw "failed to create DOM DOC";
pDoc->load("d:\\test.xml");
pDoc->get_childNodes(&pNodeList);
////// From here
pNodeList->get_length(&cnt);
cout << "LENGTH " << cnt << endl;
for(cnt = 0 ; (pNode = pNodeList->nextNode()) ; ++cnt);
cout << "Node count " << cnt <<endl;
////// to here
}
catch (string str)
{
cout << "Exception : " << str << endl;
}
catch (...)
{
cout << "Exception Unkonwn\n";
}
::CoUninitialize();
cout << "END" <<endl;
return 0;
}
///////////////////////
****************************** 1
when the test.xml is
<Book id="00322032"><Author>lookus</Author></Book>
it works well, and prints :
BEGIN
LENGTH 1
Node count 1
END
****************************** 2
however when test.xml is
<Book id="00322032"><Author>lookus</Author></Book>
<Bok id="003232"><Author>ookus</Author></Book>
it prints :
BEGIN
LENGTH 0
Node count 0
END
but it's excepted to print
BEGIN
LENGTH 2
Node count 2
END
################################# More
in msdn there is
IXMLDOMNodeList::nextNode
The nextNode method retrieves the next node in the IXMLDOMNodeList
collection.
HRESULT nextNode(
IXMLDOMNode** ppNextItem
);
but when i wrote i got "error C2660: 'nextNode' : function does not
take 1 parameters"
//////////////////////////////////
My MSN and email is ***@gmail.com.
I will appreciate your help.
here is my code
////// msxml_test.cpp
////// use MFC in a shared dll
#include <iostream>
#include <cmath>
#include <string>
#import <msxml4.dll>
#include <msxml.h>
using namespace std;
int main()
{
cout << "BEGIN" <<endl;
HRESULT hr;
long cnt;
try
{
hr = ::CoInitialize(NULL);
MSXML2::IXMLDOMDocumentPtr pDoc;
MSXML2::IXMLDOMNodeListPtr pNodeList;
MSXML2::IXMLDOMNodePtr pNode;
if(FAILED(hr))
throw "failed to com init";
hr = pDoc.CreateInstance(__uuidof(MSXML2::DOMDocument40));
if(FAILED(hr))
throw "failed to create DOM DOC";
pDoc->load("d:\\test.xml");
pDoc->get_childNodes(&pNodeList);
////// From here
pNodeList->get_length(&cnt);
cout << "LENGTH " << cnt << endl;
for(cnt = 0 ; (pNode = pNodeList->nextNode()) ; ++cnt);
cout << "Node count " << cnt <<endl;
////// to here
}
catch (string str)
{
cout << "Exception : " << str << endl;
}
catch (...)
{
cout << "Exception Unkonwn\n";
}
::CoUninitialize();
cout << "END" <<endl;
return 0;
}
///////////////////////
****************************** 1
when the test.xml is
<Book id="00322032"><Author>lookus</Author></Book>
it works well, and prints :
BEGIN
LENGTH 1
Node count 1
END
****************************** 2
however when test.xml is
<Book id="00322032"><Author>lookus</Author></Book>
<Bok id="003232"><Author>ookus</Author></Book>
it prints :
BEGIN
LENGTH 0
Node count 0
END
but it's excepted to print
BEGIN
LENGTH 2
Node count 2
END
################################# More
in msdn there is
IXMLDOMNodeList::nextNode
The nextNode method retrieves the next node in the IXMLDOMNodeList
collection.
HRESULT nextNode(
IXMLDOMNode** ppNextItem
);
but when i wrote i got "error C2660: 'nextNode' : function does not
take 1 parameters"
//////////////////////////////////
My MSN and email is ***@gmail.com.
I will appreciate your help.