student.xml文件内容:
1 int readXML(void) 2 { 3 rapidxml::file<> file("student.xml"); 4 rapidxml::xml_document<> doc; 5 doc.parse<0>(file.data()); 6 7 rapidxml::xml_node<> *root = doc.first_node(); 8 rapidxml::xml_node<> *p_node = root->first_node(); 9 for ( ; NULL != p_node; p_node = p_node->next_sibling()) 10 { 11 std::cout << p_node->name() << std::endl; 12 for (rapidxml::xml_node<> *p_temp = p_node->first_node(); NULL != p_temp; p_temp = p_temp->next_sibling()) 13 { 14 std::cout << p_temp->name() << " : " << p_temp->value() << std::endl; 15 } 16 } 17 doc.clear(); 18 19 system("pause"); 20 21 return 0; 22 }
运行结果: