//============================================================================
// Name : libxmlcpp_test.cpp
// Author : [email protected],[email protected]
// Version : 1.0
//============================================================================
#include "xmlcpp.h"
using namespace std;
using namespace xmlcpp;
int main() {
string title_text[] = { "数据结构", "路由器与交换型互联网基础", "计算机硬件技术基础", "软件质量保证与管理",
"算法设计与分析", "计算机操作系统" };
double price_text[] = { 30, 27, 25, 39, 23, 28 };
string author_text[] =
{ "严蔚敏", "程庆辉", "李继灿", "朱少民", "王红梅", "7-111-19149-1" };
node bookstore("bookstore");
for (int i(1); i < 7; ++i) {
node book("book");
book["Type"] = "必修课";
if (i != 6) {
book["ISBN"] = string("7-111-19149-") + num2str(i + 1);
} else {
book["ISBN"] = string("7-111-19149-") + num2str(1);
}
node title("title");
node author("author");
node price("price");
title.set_text(title_text[i - 1]);
author.set_text(author_text[i - 1]);
price.set_text(num2str(price_text[i - 1]));
book.push_back(title);
book.push_back(author);
book.push_back(price);
bookstore.push_back(book);
}
string file = bookstore.get_name() + ".xml";
bookstore.save(file);
node test;
test.load(file);
deque &tmp = test.find_has_text("计算");
for (size_t i = 0; i < tmp.size(); ++i) {
cout << *tmp[i] << endl;
}
return 0;
}
|