블로그 이미지
Every unexpected event is a path to learning for you.

카테고리

분류 전체보기 (2737)
Unity3D (817)
Programming (474)
Server (33)
Unreal (4)
Gamebryo (56)
Tip & Tech (228)
협업 (58)
3DS Max (3)
Game (12)
Utility (136)
Etc (96)
Link (32)
Portfolio (19)
Subject (90)
iOS,OSX (53)
Android (14)
Linux (5)
잉여 프로젝트 (2)
게임이야기 (3)
Memories (20)
Interest (38)
Thinking (38)
한글 (30)
PaperCraft (5)
Animation (408)
Wallpaper (2)
재테크 (18)
Exercise (3)
나만의 맛집 (3)
냥이 (10)
육아 (16)
Total
Today
Yesterday
04-20 00:00

'요약'에 해당되는 글 1건

  1. 2010.12.08 TinyXml 사용법 요약
예제 XML 파일 
1.<!--?xml version="1.0" ?-->     <myapp>        <welcome>Welcome to MyApp</welcome>        <farewell>Thank you for using MyApp</farewell>              <windows>         <windowname="MainFrame" w="400" h="250"y="15" x="5">       </window></windows>       <connectiontimeout="123.456000"ip="192.168.0.1">       </connection></myapp>

파일에서 읽을때
1.TiXmlDocument document;        document.LoadFile(_File_Name_);

문자열로 읽을때
1.TiXmlDocument document;        document.Parse(szXML);

Node와 Element를 가져올때
1.TiXmlElement* pRoot = document.FirstChildElement("MyApp");        if( NULL == pRoot ) return FALSE;        char* szRootName = pRoot->Value(); //Value()를 사용하면 Node의 이름을 알수있다

각 태그의 속성값 읽어올때 
여기에선 위예제의 windows 태그의 속성을 읽어본다.
1.TiXmlElement* pElement = pRoot->FirstChildElement("Windows");        char* szName = pElement->Attribute("name");         char* szX = pElement->->Attribute("x");         char* szY = pElement->->Attribute("y");         char* szW = pElement->->Attribute("w");         char* szH = pElement->->Attribute("h");

정수형으로 읽고 싶으면~
1.int x;pElement->Attribute("x", &x);

모든 속성값을 한번에 읽어올때
1.TiXmlElement* pElement = pRoot->FirstChildElement("Windows");          TiXmlAttribute* attrib = pElement ->FirstAttribute(); //pElement의 속성을 받아온다.     while(attrib)   {           const char* szAttribute = attrib->Value();             attrib = attrib->Next();         }

Child Node를 순회 할때
1.TiXmlElement* pRoot = doc.RootElement();        TiXmlElement* pChild;        for(pChild = pRoot ->FirstChildElement() ; pChild != 0 ; pChild = pChild->NextSiblingElement())        { //Node를 돌면서..        }

Save XML 
Xml 형식선언할때
1.TiXmlDocument doc;   TiXmlElement* msg; TiXmlDeclaration* decl = newTiXmlDeclaration( "1.0""""" );   doc.LinkEndChild( decl );      //결과값 : <!--?xml version="1.0" ?-->

서브 노드를 추가할때
1.TiXmlElement * root = new TiXmlElement( "MyApp" );   doc.LinkEndChild( root );

주석문장을 추가할때
1.TiXmlComment * comment = new TiXmlComment();comment->SetValue(" Settings for MyApp " );  root->LinkEndChild( comment );

Message 서브노드와 하위 노드및 데이터를 추가할때
1.TiXmlElement * msgs = new TiXmlElement( "Messages" );       root->LinkEndChild( msgs );       msg = new TiXmlElement( "Welcome");       msg->LinkEndChild( new TiXmlText( "Welcome to MyApp"));       msgs->LinkEndChild( msg );       msg = new TiXmlElement("Farewell" );       msg->LinkEndChild( new TiXmlText( "Thank you for using MyApp" ));       msgs->LinkEndChild( msg );

노드를 추가하고 Attribute를 설정할때 레벨을 맞추기 위해서 root의 하위로 추가 한것을 주의 깊게 봐야 한다.
1.TiXmlElement * windows = new TiXmlElement( "Windows" );       root->LinkEndChild( windows );       TiXmlElement * window;     window =new TiXmlElement( "Window" );       windows->LinkEndChild( window );       window->SetAttribute("name""MainFrame");     window->SetAttribute("x", 5);     window->SetAttribute("y", 15);     window->SetAttribute("w", 400);     window->SetAttribute("h", 250);

Double 값 (소수점 값) 을 설정할때
1.TiXmlElement * cxn = new TiXmlElement( "Connection" );       root->LinkEndChild( cxn );       cxn->SetAttribute("ip","192.168.0.1");     cxn->SetDoubleAttribute("timeout", 123.456); // floating point attrib

Xml파일로 저장할때
1.// 파일로 저장      doc.SaveFile("text.xml");     //문자열로..     TiXmlPrinter printer;     printer.SetStreamPrinting();     Doc.Accept( &printer );      char* pAA = printer.CStr();                    // char* 를 반환한다.     std::string str = printer.Str();                  // std::string으로 반환한다.

반응형

'Programming > TinyXML' 카테고리의 다른 글

TinyXML Read  (2) 2010.12.08
TinyXML Write  (0) 2010.12.08
XML introduce(XML 문법 설명)  (0) 2010.04.27
Tiny XML 링크  (0) 2010.04.27
Posted by blueasa
, |