[쥬니] 전환점

블로그 이미지
시작!
by eiliyuki
  • 8,825Total hit
  • 0Today hit
  • 2Yesterday hit



1. Load
TiXmlDocument doc(FILE_PATH);
doc.LoadFile();

TiXmlDocument m_XmlDoc;
if( m_XmlDoc.LoadFile(FILE_PATH) == true )
AfxMessageBox(_T("Load 성공"));


2. 값 추출??
TiXmlNode *node = doc.FirstChild("QuestList")->FirstChild("QuestIndex");
TiXmlElement *element = NULL;

while(node != NULL)
{
element = node->ToElement();
if(!element)
continue;
TCHAR buffer[256] = {0,};
const char *sCharBuffer = element->Attribute("name");


MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, sCharBuffer, strlen(sCharBuffer), buffer, 256);
((CMainFrame*)m_pMainWnd)->FillFileView(buffer);
node = node->NextSibling();
}

<?xml version="1.0" encoding="euc-kr" ?>
<QuestList>
<QuestIndex index="1" name="quest_alice"/>
<QuestIndex index="2" name="quest_zoo"/>
<QuestIndex index="3" name="quest_flower"/>
<QuestIndex index="4" name="quest_candy"/>
</QuestList>

3. xml 파일로 저장
TiXmlDocument doc;
TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "utf-8", "");
doc.LinkEndChild(decl);

TiXmlElement *root = new TiXmlElement("QuestList");
doc.LinkEndChild(root);

for(int i = 0; i < 5; i++)
{
TiXmlElement *index = new TiXmlElement("QuestIndex");
root->LinkEndChild( index );
char sIndex[10];
sprintf_s(sIndex, "%d", i);
index->SetAttribute("index", sIndex);
strcpy_s(sIndex, "hi");
index->SetAttribute("name", sIndex);
}

doc.SaveFile("xml/test.xml");



<?xml version="1.0" encoding="utf-8" ?>
<QuestList>
<QuestIndex index="0" name="hi" />
<QuestIndex index="1" name="hi" />
<QuestIndex index="2" name="hi" />
<QuestIndex index="3" name="hi" />
<QuestIndex index="4" name="hi" />
</QuestList>


TRACKBACK 0 AND COMMENT 0

ARTICLE CATEGORY

분류 전체보기 (14)
쥬니 이야기 (7)
게임 프로그래밍 (7)

RECENT TRACKBACK

CALENDAR

«   2018/10   »
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      

ARCHIVE