ホーム » 2012 » 3月 » 06

日別アーカイブ: 2012/03/06

2012年3月
 123
45678910
11121314151617
18192021222324
25262728293031

カテゴリー

アーカイブ

ブログ統計情報

  • 77,353 アクセス



XML の読込テスト

// L_xml_2.cpp : コンソール アプリケーション用のエントリ ポイントの定義
//

#include “StdAfx.h”
#include “L_xml_2.h”

#import <msxml.dll> named_guids

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

BOOL TestXML (void)
{
HRESULT hr = ::CoInitialize(NULL) ;
if (FAILED(hr)) { return FALSE ; }
{
MSXML::IXMLDOMDocumentPtr pDoc = NULL ;
hr = pDoc.CreateInstance(MSXML::CLSID_DOMDocument) ;
if (FAILED(hr)) { return FALSE ; }
CString loadFile = _T(“test.xml”) ;
{
if (pDoc->load(LPCTSTR(loadFile)) == VARIANT_TRUE) {
printf(“%s\r\n”,(LPCSTR)pDoc->xml) ;
{
MSXML::IXMLDOMElementPtr root = pDoc->documentElement ;
CString tagN = LPCTSTR(root->tagName) ;
CString text = LPCTSTR(root->text) ;
printf(“<%s>%s\r\n”,tagN,text) ;
MSXML::IXMLDOMNodeListPtr nodeL = root->childNodes ;
for (int index=0 ; index<nodeL->Getlength() ; index++) {
MSXML::IXMLDOMElementPtr child = nodeL->Getitem(index) ;
CString tagN = LPCTSTR(child->tagName) ;
CString text = LPCTSTR(child->text) ;
printf(“<%s>%s\r\n”,tagN,text) ;
}
}
}
else {
printf(_T(“error … %s\r\n%s\r\n”),loadFile,(LPCSTR)pDoc->parseError->Getreason()) ;
}
}
}
::CoUninitialize() ;
return TRUE ;
}

/////////////////////////////////////////////////////////////////////////////
// 唯一のアプリケーション オブジェクト

CWinApp theApp;

using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// MFC の初期化および初期化失敗時のエラーの出力
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: 必要に応じてエラー コードを変更してください。
cerr << _T(“Fatal Error: MFC initialization failed”) << endl;
nRetCode = 1;
}
else
{
/*
// TODO: この位置にアプリケーションの動作を記述してください。
CString strHello;
strHello.LoadString(IDS_HELLO);
cout << (LPCTSTR)strHello << endl;
*/

TestXML() ;
}
return nRetCode;
}

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.