Xmlcpp support Convenient traversal search, the algorithm is efficient and robust. Can traverse search node name, node attribute key, node attribute value, and node literal text. Except that the key search needs to match exactly, the rest of the search only needs to provide a contiguous field of the content being searched.
Method List:
- Find_has_name
- Find_has_key
- Find_has_value
- Find_has_text
Here's a simple example.
First, you generate an XML file that reads as follows:
| The code is as follows |
Copy Code |
| <bookstore> <book isbn= "7-111-19149-2" type= "compulsory course" > <title> Data Structure </title> <author> Min </author> <price>30</price> </book> <book isbn= "7-111-19149-3" type= "compulsory course" > <title> router and Exchange-based Internet </title> <author> Cheng Qinghui </author> <price>27</price> </book> <book isbn= "7-111-19149-4" type= "compulsory course" > <title> Computer hardware Technology base </title> <author> Li Jizan </author> <price>25</price> </book> <book isbn= "7-111-19149-5" type= "compulsory course" > <title> Software Quality assurance and management </title> <author> Zhu Shaomin </author> <price>39</price> </book> <book isbn= "7-111-19149-6" type= "compulsory course" > <title> algorithm design and Analysis </title> <author> Wang </author> <price>23</price> </book> <book isbn= "7-111-19149-1" type= "compulsory course" > <title> Computer operating System </title> <author>7-111-19149-1</author> <price>28</price> </book> </bookstore> |
The demo code is as follows:
| The code is as follows |
Copy Code |
| //============================================================================ Name:libxmlcpp_test.cpp Author:mathsdk@163.com,numcpp@126.com version:1.0 //============================================================================
#include "Xmlcpp.h"
using namespace Std; using namespace Xmlcpp;
int main () {
String title_text[] = {"Data structure", "routers and switched Internet Basics", "Fundamentals of computer hardware Technology", "Software quality assurance and management", "Algorithm design and Analysis", "Computer operating system"}; Double price_text[] = {30, 27, 25, 39, 23, 28}; String author_text[] = {"Min", "Cheng Qinghui", "Li Jizan", "Zhu Shaomin", "Wang", "7-111-19149-1"};
Node Bookstore ("Bookstore");
for (int i (1); I < 7; ++i) {
Node Book ("Book"); book["Type"] = "compulsory course"; 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<node*> &tmp = Test.find_has_text ("calculation"); for (size_t i = 0; i < tmp.size (); ++i) { cout << *tmp[i] << Endl; }
return 0; } |
Results
Search results:
IE9 file Browsing:
Eclipse XML Browsing files:
Xmlcpp traversal Search, is so simple!