Using XML AS A DATA Storage Format as a data storage format with XML
Questions raised:
What is the meaning of using XML in the local application?
Reply:
Introduction
The development of the Web industry leads to the development of traditional technologies and gradually balanced between the client and the server. The browser, protocol, and new standards for the scripting language have replaced all other places. The next step is an XML-scalable markup language that it is believed that it will replace HTML and do the format of the main web application to transfer files. XML is a format for converting data to each client. The web server or network client will be combined with XML data and a style sheet and generated a very clear HTML code to display data.
In other aspects, you can expand your program's functionality with XML language. Considering that XML is a universal data storage format, this problem is actually more flexible than DBF or other relational database formats.
Why can you use XML as the only advanced method to create a web page? XML is more versatile than a single markup language and more flexible. You can create your own data format or network protocol with tags and interfaces you have invented.
Below you will see an example of an unbarily XML usage, which is designed with Borland Delphi.
analysis
Your program needs to store some data on a file or transfer data to another computer. You can save your data in a text file or some defined format file. You have to write code to support this format. When changing the data structure, you must modify the code. In some cases you can't consider whether this format is standard, and other developers may not support your format.
Based on XML to design your data storage and conversion, you will get the following benefits:
l Determine and supported grammar standards;
l Read and write the general program interface of the XML file;
l Flexible data structure;
l available web technology;
Data format with XML is in a bad place:
l and the usual database is not too, XML text does not have a predetermined structure.
In many cases the entire XML file is loaded into memory, it is only available for small files;
l There is no security setting in XML, so you have to encrypt and decrypt the XML files.
l XML is stored in text format, so you have to convert all fields to text format before storing text files.
There are many ideal ways in delphi to perform this protocol to design a PASCAL object and an interface between XML code. The purpose is to store an instance of the Pascal class in the XML format and can recover instances from the XML file.
Separate the "Pascal Object to XML" interface, use two interfaces: "Pascal object to data object" and "data object to XML" are a good way (see Figure 1).
I can't think of a simple solution to extend some Pascal classes with XML interfaces. Then use trouble, let us create a new class to store and manage an object's properties and data fields. A developer will need to write additional code to move data between Pascal objects and data objects.
Figure 1, XML data interface
design
Our mission is to perform two unrestricted interfaces: "Pascal objects to data objects" and "data objects to XML" interfaces.
The first interface must enable a developer to copy some of the data structures of some classes and instances of the SPO class. "SP0" is a standard Pascal object. The SPO class provides a data container and sets the method to store and receive data.
The second interface is to perform a regular setting to convert the SPO object to XML text and VISA VERSA.
Design SPO interface
The main purpose of the SPO class is to store and provide access data fields and properties. Because of this, create a convenient data access interface to be more important than optimizing data storage methods. Thereafter, we will not affect the interface after changing the data storage method.
I started to define data types to be supported by our interface. Only five data types we have to consider are in our model:
l string (string type)
l numeric (numeric)
l Date (date)
l Boolean (Boolean)
l Object (object)
"Object" data type allows us to use nested an object to another object to create a Complex data structure. In Figure 2, you can see an example of a data object structure:
Figure 2, data object model
To access data in our object we can use traditional methods - to re-read the object from it, to obtain object features:
Var o: tspoPOOBJECT; P: Tspoproperty; s: string; begin p: = anObject.propbyName ['Career Position']; o: = p.TheObject; s: = p.PropbyName ['title']. value; end;
The same length must be added to an object.