[code]
CParserXML x;
if (x.Load(L"./btn/btnInfo.xml"))
{
AfxMessageBox(x.GetAttributeData(L"//normal//left"));
}
Example code (XML)
<?xml version="1.0"?>
<image>
<directory>btn</directory>
<normal>
<left>normal_left.png</left>
<center>normal_cen.bmp</center>
<right>normal_right.png</right>
</normal>
<over>
<left>over_left.png</left>
<center>over_cen.bmp</center>
<right>over_right.png</right>
</over>
<active>
<left>active_left.png</left>
<center>active_cen.bmp</center>
<right>active_right.png</right>
</active>
</image>
[/code]
[code]
// DATE : February 14, 2007
// CODER : aucd29 (aucd29@gmail.com)
//
// Require
// --------------------------------------------------------
// MSXML
//
// XML Reference
// --------------------------------------------------------
// Link : http://www.w3.org
//
//
// ---------------------------------------------------------
// NOTE : February 16, 2007
// ---------------------------------------------------------
// * 기존에 XML 관련 내용들은 왜 모두 -_ - Automation 을
// 체크해서 사용하는 방법론으로 흘러갔는지 -_ -모르겠지만
// (대략 간단하다는 이유인 것 같았다.)
// 나는 그 옵션 사용해서 아직은 플그램을 하지 않아서
// 다른 방법이 필요했다. 고로 만들었다 -_ -
//
// * 단순히 데이터를 읽기 위해서 생성하였고 그 이상에
// 기능은 없다 그 때 그 때 필요할 때 추가하리라.
//
#include "StdAfx.h"
#include "ParserXML.h"
CParserXML::CParserXML(void)
: m_pDocument(NULL)
, m_pElement(NULL)
{
}
CParserXML::~CParserXML(void)
{
}
int CParserXML::Load(CString szFile)
{
m_hr = CoInitialize(NULL);
if (FAILED(m_hr))
{
AfxMessageBox(L"CoInitialize Fail");
return false;
}
m_hr = CoCreateInstance(MSXML::CLSID_DOMDocument, NULL,
CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,
MSXML::IID_IXMLDOMDocument, (LPVOID*)&m_pDocument);
if (!m_pDocument)
{
AfxMessageBox(L"CoCreateInstance Fail");
return false;
}
BSTR bstr = NULL;
bstr = szFile.AllocSysString();
m_pDocument->put_async(VARIANT_FALSE);
VARIANT_BOOL varOkay = m_pDocument->load(bstr);
SysFreeString(bstr);
if (varOkay)
{
return true;
}
else
{
AfxMessageBox(L"Error : File Not Found (" + szFile + L"), <XML PARSER>");
exit(1);
}
return false;
}
CString CParserXML::GetAttributeData(CString szNodeName)
{
// 원하는 XML 요소에 데이터를 가져온다
// 트리 구조이므로 트리에 구분은 '//' 로 할 수 있다
// 예
// <normal>
// <center>test</center>
// </normal>
// 의 구조라면은 GetAttributeData에서는
//
// "//normal//center" 로 해당 위치에 데이터를
//
// 가져올 수 있다.
// 쉽지 않는가.. 어제 한 3시간 골치 아픈게 사라지더라.
// 근데 먼놈에 관련 함수가 그리 많던지 -_ -;
//
BSTR bstrNodeName = NULL;
BSTR bszNodeValue = NULL;
CString szNodeValue;
bstrNodeName = szNodeName.AllocSysString();
m_pElement = m_pDocument->selectSingleNode(bstrNodeName);
m_pElement->get_text(&bszNodeValue);
szNodeValue.Format(L"%s", bszNodeValue);
SysFreeString(bszNodeValue);
return szNodeValue;
}
[/code]
[code]
#pragma once
// MSXML을 사용하기 위해서 DLL 을 임포트 한다.
#import "msxml.dll" named_guids
class CParserXML
{
protected:
HRESULT m_hr;
MSXML::IXMLDOMDocument* m_pDocument;
MSXML::IXMLDOMElementPtr m_pElement;
public:
CParserXML(void);
~CParserXML(void);
int Load(CString szFile);
CString GetAttributeData(CString szNodeName);
};
[/code]
CParserXML x;
if (x.Load(L"./btn/btnInfo.xml"))
{
AfxMessageBox(x.GetAttributeData(L"//normal//left"));
}
Example code (XML)
<?xml version="1.0"?>
<image>
<directory>btn</directory>
<normal>
<left>normal_left.png</left>
<center>normal_cen.bmp</center>
<right>normal_right.png</right>
</normal>
<over>
<left>over_left.png</left>
<center>over_cen.bmp</center>
<right>over_right.png</right>
</over>
<active>
<left>active_left.png</left>
<center>active_cen.bmp</center>
<right>active_right.png</right>
</active>
</image>
[/code]
[code]
// DATE : February 14, 2007
// CODER : aucd29 (aucd29@gmail.com)
//
// Require
// --------------------------------------------------------
// MSXML
//
// XML Reference
// --------------------------------------------------------
// Link : http://www.w3.org
//
//
// ---------------------------------------------------------
// NOTE : February 16, 2007
// ---------------------------------------------------------
// * 기존에 XML 관련 내용들은 왜 모두 -_ - Automation 을
// 체크해서 사용하는 방법론으로 흘러갔는지 -_ -모르겠지만
// (대략 간단하다는 이유인 것 같았다.)
// 나는 그 옵션 사용해서 아직은 플그램을 하지 않아서
// 다른 방법이 필요했다. 고로 만들었다 -_ -
//
// * 단순히 데이터를 읽기 위해서 생성하였고 그 이상에
// 기능은 없다 그 때 그 때 필요할 때 추가하리라.
//
#include "StdAfx.h"
#include "ParserXML.h"
CParserXML::CParserXML(void)
: m_pDocument(NULL)
, m_pElement(NULL)
{
}
CParserXML::~CParserXML(void)
{
}
int CParserXML::Load(CString szFile)
{
m_hr = CoInitialize(NULL);
if (FAILED(m_hr))
{
AfxMessageBox(L"CoInitialize Fail");
return false;
}
m_hr = CoCreateInstance(MSXML::CLSID_DOMDocument, NULL,
CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,
MSXML::IID_IXMLDOMDocument, (LPVOID*)&m_pDocument);
if (!m_pDocument)
{
AfxMessageBox(L"CoCreateInstance Fail");
return false;
}
BSTR bstr = NULL;
bstr = szFile.AllocSysString();
m_pDocument->put_async(VARIANT_FALSE);
VARIANT_BOOL varOkay = m_pDocument->load(bstr);
SysFreeString(bstr);
if (varOkay)
{
return true;
}
else
{
AfxMessageBox(L"Error : File Not Found (" + szFile + L"), <XML PARSER>");
exit(1);
}
return false;
}
CString CParserXML::GetAttributeData(CString szNodeName)
{
// 원하는 XML 요소에 데이터를 가져온다
// 트리 구조이므로 트리에 구분은 '//' 로 할 수 있다
// 예
// <normal>
// <center>test</center>
// </normal>
// 의 구조라면은 GetAttributeData에서는
//
// "//normal//center" 로 해당 위치에 데이터를
//
// 가져올 수 있다.
// 쉽지 않는가.. 어제 한 3시간 골치 아픈게 사라지더라.
// 근데 먼놈에 관련 함수가 그리 많던지 -_ -;
//
BSTR bstrNodeName = NULL;
BSTR bszNodeValue = NULL;
CString szNodeValue;
bstrNodeName = szNodeName.AllocSysString();
m_pElement = m_pDocument->selectSingleNode(bstrNodeName);
m_pElement->get_text(&bszNodeValue);
szNodeValue.Format(L"%s", bszNodeValue);
SysFreeString(bszNodeValue);
return szNodeValue;
}
[/code]
[code]
#pragma once
// MSXML을 사용하기 위해서 DLL 을 임포트 한다.
#import "msxml.dll" named_guids
class CParserXML
{
protected:
HRESULT m_hr;
MSXML::IXMLDOMDocument* m_pDocument;
MSXML::IXMLDOMElementPtr m_pElement;
public:
CParserXML(void);
~CParserXML(void);
int Load(CString szFile);
CString GetAttributeData(CString szNodeName);
};
[/code]