Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - XML exception( my MSN : lookus.cn@gmail.com) [Thread Next] RE: XML exception( my MSN : lookus.cn@gmail.com)To: NULL Date: 5/2/2006 2:29:00 PM
If your xml file is exactly like
<Book id="00322032"><Author>lookus</Author></Book>
<Bok id="003232"><Author>ookus</Author></Book>
Then it is an invalid xml file. (There must be only one root node in the xml
file and your opening and closing element names should match).
--
Sih Huseyin Ulger [MSFT]
MSXML Dev
"lookus" wrote:
> 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 lookus.cn@g....
> I will appreciate your help.
>
>
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
