Add some doctype information in Delphi operation XML

Source: Internet
Author: User

Recently, other project teams encountered a small problem of exporting XML data, because I was familiar with XML operations before, and naturally found my help ending. In fact, Delphi is very convenient to operate XML. The problem is that their xml header must be available! For example, the following XMLCode:

<? XML version = "1.0" encoding = "gb2312" ?>
<! Doctype math system "http://www.w3.org/Math/DTD/mathml1/mathml.dtd" >
< Root >
< Test >
< Add Key = "-1" Filename = "Ofile" />
</ Test >
</ Root >

 

For the good operations in C #, Delphi has relatively few codes and no results can be found on Google. So I checked Delphi's nativexml. Pas.Source codeWe found that there is a definition of xedoctype, which is exactly what we are looking. Haha ..

The Delphi code for defining XML doctype is as follows:

Uses nativexml 

Procedure Tform1.button1click (Sender: tobject );
VaR
XML: tnativexml;
N_bs: txmlnode;
Begin
XML: = Tnativexml. createname ( ' Root ' );
XML. encodingstring: =   ' Gb2312 ' ;
XML. xmlformat: = Xfreadable;

// Normal XML section
N_bs: = XML. Root. nodenew ( ' Test ' );
N_bs: = N_bs.nodenew ( ' Add ' );
N_bs.writeattributestring ( ' Key ' , ' -1 ' );
N_bs.writeattributestring ( ' Filename ' , ' Ofile ' );

//Add<! Doctype?>Part
N_bs:=Txmlnode. createtype (XML, xedoctype );
N_bs.valuedirect:= 'Math System "http://www.w3.org/Math/DTD/mathml1/mathml.dtd"';
XML. rootnodelist. nodeinsert (1, N_bs );

XML. savetofile ('1. xml ');

End; 

In this way, the above XML file is output.

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.