xml data  읽기


#include <iostream>

#include <string>

#include "tinyxml2.h"

using namespace tinyxml2;

using namespace std;


int main()

{

char buf[] = "\

<TESTNODE1 version='1.0'>\n\

    <TESTNODE2 value='hello' />\n\

    <TESTNODE3>\

hello, testnode3\

    </TESTNODE3>\n\

</TESTNODE1>";

XMLError xmlerr=XML_NO_ERROR;

XMLDocument doc;

xmlerr = doc.Parse(buf);

if (xmlerr == XML_SUCCESS)

{

cout << "Parse Success" << endl;

XMLElement *pelem = doc.FirstChildElement();

cout << pelem->Name();

if(pelem->GetText() != NULL)

cout << "    text:" << pelem->GetText() << endl;

else

cout << endl;

for (const XMLAttribute* pattr = pelem->FirstAttribute(); pattr != NULL; pattr = pattr->Next())

{

cout << pattr->Name() << " = " << pattr->Value() << endl;

}

pelem = pelem->FirstChildElement();

while(pelem != NULL)

{

cout << pelem->Name();

if(pelem->GetText() != NULL)

cout << "    text:" << pelem->GetText() << endl;

else

cout << endl;

for (const XMLAttribute* pattr = pelem->FirstAttribute(); pattr != NULL; pattr = pattr->Next())

{

cout << pattr->Name() << " = " << pattr->Value() << endl;

}

pelem = pelem->NextSiblingElement();

}

}

else

cout << "Parse Error : " << xmlerr << endl; 

    return 0;

}




Posted by AlwaysNR
BLOG main image
잡동사니 by AlwaysNR

공지사항

카테고리

분류 전체보기 (39)
사진 (9)
일상 (5)
프로그래밍 (15)
고발 (0)
끄적끄적 (7)
좋은 곳 (1)
조물딱조물딱 (1)

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

Total :
Today : Yesterday :