1、下载并加载tintXML2库文件http://download.csdn.net/detail/yimengchenxi/8886991
2、实现的代码如下所示:
(1)文件如下:
(2)解析的代码如下:
//对XML文件进行解析
void ParseXML(char *fileName)
{
XMLDocument *myDocument = new XMLDocument();
myDocument->LoadFile(fileName);
if (myDocument->ErrorID())
{
cout << "有误!";
return;
}
//根节点的读取
XMLElement *RootElement = myDocument->FirstChildElement();
//cout << RootElement->Value() << endl;
XMLElement *FirstBook = RootElement->FirstChildElement();
while (FirstBook)
{
XMLElement *BookName = FirstBook->FirstChildElement();
//获取文本
cout << BookName->GetText() << endl;
XMLElement *BookPrice = BookName->NextSiblingElement();
cout << BookPrice->GetText() << endl;
FirstBook = FirstBook->NextSiblingElement();
}
}