Analysis of Duilib source code XML Class CMarkup & Cmarkupnode header file

Source: Internet
Author: User

XML is used more or less, and the Duilib interface is also implemented through XML configuration.

Duilib provides cmarkkup and Cmarkupnode class parsing XML, which is more convenient to use, more curious about how it is implemented, if you write a

Analytic and need how to structure, the road of architecture is still very remote ...

First of all, look at the file, CMarkup is mainly used to split the XML, to determine whether the XML format is correct; Cmarkupnode is mainly to divide the cmarkup XML, get the attributes in the node,

Supports up to 64 properties

1 enum2 {3Xmlfile_encoding_utf8 =0,//define encoding, use UTF8 by default 4Xmlfile_encoding_unicode =1,5Xmlfile_encoding_asni =2,6 };7 8 classCMarkup;9 classCmarkupnode;Ten  One  A classUilib_api cmarkup//actually more easy to read  - { -FriendclassCmarkupnode; the  Public: -CMarkup (LPCTSTR pstrxml =NULL); -~cmarkup (); -  +     BOOLLoad (LPCTSTR pstrxml); -     BOOLLoadfrommem (byte* pbyte, DWORD dwsize,intencoding =Xmlfile_encoding_utf8);//load parsing from memory +     BOOLLoadFromFile (LPCTSTR Pstrfilename,intencoding =Xmlfile_encoding_utf8);//load parsing from file A     voidRelease (); at     BOOLIsValid ()Const; -  -     voidSetpreservewhitespace (BOOLBpreserve =true); -     voidGetlasterrormessage (LPTSTR pstrmessage, size_t Cchmax)Const; -     voidGetlasterrorlocation (LPTSTR pstrsource, size_t Cchmax)Const; -  in Cmarkupnode getroot (); -  to Private: +typedefstructtagxmlelement -     { the ULONG IStart; //node start pointer position  * ULONG ichild; //First child node pointer position  $ ULONG INext; //Next sibling node pointer position Panax Notoginseng ULONG iparent; //Father node pointer position  - ULONG IData; the location of the end of the//node property  the } XMLELEMENT; +  A LPTSTR M_pstrxml; //xml Memory Start location  thexmlelement*m_pelements; //Array storage node information  + ULONG m_nelements; - ULONG m_nreservedelements; $TCHAR m_szerrormsg[ -]; $TCHAR m_szerrorxml[ -]; -     BOOLM_bpreservewhitespace; -  the Private: -     BOOL_parse ();Wuyi     BOOL_parse (lptstr&Pstrtext, ULONG iparent); //Parse XML function, mainly parse here  thexmlelement*_reserveelement (); //If the array is not long enough, expand  -Inlinevoid_skipwhitespace (lptstr& pstr)Const; WuInlinevoid_skipwhitespace (lpctstr& pstr)Const; -Inlinevoid_skipidentifier (lptstr& pstr)Const; AboutInlinevoid_skipidentifier (lpctstr& pstr)Const; $     BOOL_parsedata (lptstr& pstrtext, lptstr& Pstrdata,Charcend); //Parse the value of the property  -     void_parsemetachar (lptstr& Pstrtext, lptstr&pstrdest); //Handling some escape symbols  -     BOOL_parseattributes (lptstr&pstrtext); //parsing Properties  -     BOOL_failed (LPCTSTR pstrerror, LPCTSTR pstrlocation =NULL); A }; +  the  - classUilib_api Cmarkupnode $ { theFriendclassCMarkup; the Private: the Cmarkupnode (); theCmarkupnode (cmarkup* Powner,intIPos); -  in  Public: the     BOOLIsValid ()Const; the  About Cmarkupnode GetParent (); the Cmarkupnode getsibling (); the Cmarkupnode getchild (); the cmarkupnode getchild (LPCTSTR pstrname); +  -     BOOLHassiblings ()Const; the     BOOLHasChildren ()Const;BayiLPCTSTR GetName ()Const; theLPCTSTR GetValue ()Const; //This gets the value of the node, it returns the Idata is actually the end of the property  the  -     BOOLhasattributes (); -     BOOLHasattribute (LPCTSTR pstrname); the     intGetattributecount (); theLPCTSTR Getattributename (intiIndex); theLPCTSTR Getattributevalue (intiIndex); the lpctstr Getattributevalue (LPCTSTR pstrname); -     BOOLGetattributevalue (intIIndex, LPTSTR pstrvalue, size_t cchmax); the     BOOLGetattributevalue (LPCTSTR pstrname, LPTSTR pstrvalue, size_t cchmax); the  the Private:94     void_mapattributes (); //Map the previously segmented XML into m_aattributes and store  it. the  the     enum{max_xml_attributes = - }; the 98typedefstruct About     { - ULONG Iname;101 ULONG Ivalue;102 } XmlAttribute;103 104     intM_ipos; the     intm_nattributes;106 XmlAttribute m_aattributes[max_xml_attributes];107cmarkup*M_powner; //point to CMarkup Pointer, node properties and values are obtained from here 108};

Simply say the work of these two classes, first loaded with CMarkup XML into memory, in the division of the string, the relationship between the node tree (through xmlelement* point to the node location relationship, Istart Point to the beginning of the node, Idata point to the end of the node, Ichild, Inext,iparent the relationship between storage nodes), getting the node is the attribute is extracted by cmarkupnode based on the value of the node Istart,idata. Cmarkupnode used to get the attribute value and get the father, brother, son node, familiar with the role of these two classes, the use of more convenient, specific implementation of the next detailed description.

Analysis of Duilib source code XML Class CMarkup & Cmarkupnode header file

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.