Introduction to XML read-write library xmlcpp in asp.net (d): Traversal search

Source: Internet
Author: User

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:

    1. Find_has_name
    2. Find_has_key
    3. Find_has_value
    4. 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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.