XML (extensible Markup Language Extensible Logo language) is the most eye-catching word in recent years in information magazines and websites. Large and small information products are scrambling to catch up with it, lest the fast train. Has a good reputation of the Blue (Borland) series development platform is no exception, since the 6.0 version of the integration of the XML component package, because of its use of Msxmldom parser, compared to the widely used Xmlparser parser, msxmldom More specification, Chinese compatibility better (element name , attribute names are supported in Chinese), are favored by developers. To help beginners quickly master the XML programming in Delphi, the author features this article for communication.
The author explains the steps of XML programming through an example of XML file, which can be easily understood by readers with the basic concepts of node, element and attribute. The XML file structure I want to read is shown below, named Input.xml.
<?xml version="1.0" encoding="GB2312"?>
<学生花名册>
<学生 性别 = "男">
<姓名>李华</姓名>
<年龄>14</年龄>
<电话>6287555</电话>
</学生>
<学生 性别 = "男">
<姓名>张三</姓名>
<年龄>16</年龄>
<电话>8273425</电话>
</学生>
</学生花名册>
The first line of the Input.xml file is the version description of the XML, the attribute encoding declares which character set is used, the default Unicode encoding (UTF-8 or UTF-16), and the Chinese GB2312 code here. The second line of "student roster" is the root element. The following defines two student elements, and the student has three child elements nested below, which is a further explanation for the student. Corresponding to this, we define the following student data structure in Delphi, "//" After the text is the description of the variable or statement, hereinafter.
TStudent = class {学生}
sex : string; //学生性别
name : string; //学生姓名
age : integer; //学生年龄
phone: string; //电话号码
end;