Добрый день Есть xml файл. | Цитата | <?xml version="1.0" ?> <init_map> <team_Group> <team name = "AAA" color = "blue"/> <unit type = "tank" x = "5" y = "45"/> <unit type = "Army" x = "45" y = "5"/> <unit type = "Army" x = "12" y = "9"/> </team_Group> <team_Group> <team name = "BBB" color = "green"/> <unit type = "tank" x = "5" y = "45"/> <unit type = "Army" x = "45" y = "5"/> <unit type = "Army" x = "12" y = "9"/> </team_Group> <create_vector raw_i="5" col_j="5" /> <values index_x="0" index_y="0" value_element="forest_hill"/> <values index_x="0" index_y="1" value_element="hill"/> </init_map>
|
не как не получается пробежатся(и причитать) по всему файлу.(включая child ы) вот сообствнно и код | Код |
void load(const char *pfilename){ TiXmlDocument doc(pfilename); if (!doc.LoadFile()) return;
TiXmlNode * hDoc = doc.RootElement(); TiXmlElement* pElem,*ptemp_elem; TiXmlHandle hRoot(0);
pElem = hDoc->FirstChildElement(); if(!pElem) return; hRoot = TiXmlHandle(pElem); while(pElem){ TiXmlAttribute *pAttribut = pElem->FirstAttribute(); ptemp_elem = pElem; if((ptemp_elem = hRoot.FirstChildElement("team_Group").FirstChild().Element())!=NULL ){ //create object team for(ptemp_elem;ptemp_elem;ptemp_elem = ptemp_elem->NextSiblingElement()){ if(0 == strcmp(ptemp_elem->Value(),"team")){ TiXmlAttribute * pAttr = ptemp_elem->FirstAttribute(); //read team property while(pAttr){ if(0 == strcmp(pAttr->Name(),"name")) string str_n = pAttr->Value(); if(0 == strcmp(pAttr->Name(),"color")) string str_c = pAttr->Value(); pAttr = pAttr->Next(); } } if(0 == strcmp(ptemp_elem->Value(),"unit")){ //craete unit and fill its property TiXmlAttribute * pAttr = ptemp_elem->FirstAttribute(); while(pAttr){ if(0 == strcmp(pAttr->Name(),"type")) string str_n = pAttr->Value(); if(0 == strcmp(pAttr->Name(),"x")) string x = pAttr->Value(); if(0 == strcmp(pAttr->Name(),"y")) string y = pAttr->Value(); pAttr = pAttr->Next(); }
} } } if(0 == strcmp(pElem->Value(),"create_vector")){ //init vector TiXmlAttribute * pAttr = ptemp_elem->FirstAttribute(); while(pAttr){ if(0 == strcmp(pAttr->Name()," raw_i")) string raw = pAttr->Value(); if(0 == strcmp(pAttr->Name()," raw_j")) string raw_j = pAttr->Value(); pAttr = pAttr->Next(); } } if(0 == strcmp(pElem->Value(),"value")){ //init vector TiXmlAttribute * pAttr = ptemp_elem->FirstAttribute(); while(pAttr){ if(0 == strcmp(pAttr->Name(),"index_x")) string i = pAttr->Value(); if(0 == strcmp(pAttr->Name(),"index_y")) string j = pAttr->Value(); if(0 == strcmp(pAttr->Name(),"value_element")) string str_ter = pAttr->Value(); pAttr = pAttr->Next();
}
} pElem = pElem->NextSiblingElement(); }
|
--------------------
| Цитата | Многие вещи нам непонятны не оттого, что наши понятия слабы, а оттого, что данные вещи не входят в круг наших понятий.
|
|