Detailed description of nativexml Database Technology

Source: Internet
Author: User

Originally, I used the txmldocument class that comes with Delphi to read and write XML files. Although it is troublesome, It is not bad in terms of functions. There is only one thing that makes me really uncomfortable-every time I create a txmldocument class instance, I must input a tcomponent object. This means that if I encapsulate the read and write of XML files into a class, the tcomponent object must also be input when the custom class is created.
I tried many methods, but they could not be avoided. I finally tried to find the nativexml library online.
After the download, I immediately opened the demo and looked at it. Cool. When creating tnativexml, I only needed to input the XML file path. Then I was pleasantly surprised when I looked down. It has encapsulated most operations and can serialize any object.
For example, you can store the entire form into an XML file through the tsdxmlobjectwriter = Class (tpersistent) class and read it again next time. This makes it easy to remotely transmit objects.
The following is an example of using the nativexml Library:
Target XML structure:
<Bookshift>
<Book author = "test_author">
<Date> 2000-01-01 </date>
</Book>
</Bookshift>

Delphi code:
Procedure writetest;
VaR
XML: tnativexml;
N_bs: txmlnode;
Begin
// Create a root node
XML: = tnativexml. createname ('bookshift ');

XML. encodingstring: = 'gb2312 ';
// The output style is readable.
XML. xmlformat: = xfreadable;

// Create a book Node
N_bs: = xml. Root. nodenew ('book ');
// Write the attributes of the book Node
N_bs.writeattribuitestring ('author', 'test _ author ');
// Create the date node of the book node and write the value
N_bs.writestring ('date', '2017-01-01 ');

XML. savetofile ('test. xml ');
End;

Open the test. xml file and check the format above.
It's easy. I used this library to rewrite the original XML Parser class, saving about 40% of the Code.

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.