An easy-to-manipulate XML parsing package (c + +) based on simple recursive thinking

Source: Internet
Author: User

Technical points:

1. Basic XML Parsing library: TinyXML

2, Xmltree class

3. Overload [], Return Xmltree class

4. Implement the Count function to return the number of this level of directory child nodes


For the following cmystring Strrequestxml: (in order to illustrate the function, the request node is divided into two parts written)

<?xml version= ' 1.0 ' encoding= ' utf-8 '? ><request Version = ' 1.0 ' name = ' Updatemainview ' ><request>< Requesttype>updateui</requesttype><view><viewtype>mainview</viewtype><viewid> View_1</viewid><event>click</event><listview><id>listview_mainview</id> <selectedId>item_2</selectedId></listView></view></request>

can achieve:
1. Implement string-based constructors: XmlTree *requestxml = new XmlTree (strrequestxml);
2. Overload [] Implements sub-object array of child XmlTree: XmlTree **subviewrequestxml = requestxml["Request"][1]["view"];
3, the realization when Xmltree only one node can be strong to turn into cmystring:requestxml["request"][1]["View" ["Event"]. CMyString (), and can be get/set and directly assigned
4, the implementation of the number of sub-nodes count:requestxml["request"][1]. Count () = = 2
5. Node access for non-tree representations: reuestxml["Request"][0]["version"] = = "1.0"
6, extension implementation, you can consider the extension: Xmltree insert and delete: requestxml["View"].insert (Subviewrequestxml)


A secondary pointer represents the first element of a primary pointer array that can be turned around, no problem, just like a two-dimensional array arrayxy[][] Arrayxy = = Arrayxy[0];
So the above xmltree **subviewrequestxml = requestxml["Request"][0]["view"];
Can be written as XmlTree *subviewrequestxml = requestxml["Request"][0]["view"]; Can also be written as xmltree *subviewrequestxml = requestxml["Request" ["View"];

An easy-to-manipulate XML parsing package (c + +) based on simple recursive thinking

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.