資料集生成Xml 格式檔案

2021-06-19 01:51:28 字數 2779 閱讀 2719

//資料集生成xml 格式檔案

function makexml(dataset:tadodataset;xmlrootname:string):integer;

vari   : integer;

xml : string;

temp:variant;

doc : ixmldomdocument;

root,child,child1 : ixmldomelement;

a:tfieldtype;

begin

tryif dataset.active =false then dataset.active:=true;

xml:=xmlrootname;

//doc --> root --> first level(child) --> second level(child1) --> child1 value

doc  :=  codomdocument60.create;   // 呼叫 ms xml 6.0 控制項建立 doc --> ixmldomdocument3

//設定 xml 根節點

root := doc.createelement(xml);    //建立 ixmldomdocument 的根節點元素 root --> ixmldomelement

// 生成 xml 檔案過程

//while not table.eof do

with dataset do

begin

while not eof do

begin

//新增第一層 節點 , records

child:= doc.createelement('records');         //建立 root 根節點的第一層節點元素 child --> ixmldomelement

for i:=0 to fieldcount-1 do

begin

//新增第二層子節點 欄位名與值

child1:=doc.createelement(fields[i].fieldname);  //建立 child 第一層節點元素的第二層節點元素 child1 --> ixmldomelement

//檢查字段 型別 ,賦值給 temp

case tfieldtype(ord(fields[i].datatype)) of

ftstring,ftwidestring:

begin

if fields[i].asstring ='' then

temp :=' '  //put a default string

else

temp := fields[i].asstring;

end;

ftinteger,ftlargeint, ftword, ftsmallint:

begin

if fields[i].asinteger > 0 then

temp := inttostr(fields[i].asinteger)

else

temp := '0';

end;

ftfloat, ftcurrency, ftbcd:

begin

if fields[i].asfloat > 0 then

temp := floattostr(fields[i].asfloat)

else

temp := '0';

end;

ftboolean:

begin

if fields[i].value then

temp:= true

else

temp:= false;

end;

ftdate:

begin

if (not fields[i].isnull) or

(length(trim(fields[i].asstring)) > 0) then

temp := formatdatetime('mm/dd/yyyy',fields[i].asdatetime)

else

temp:= '01/01/2000'; //預設日期

end;

ftdatetime:

begin

if (not fields[i].isnull) or

(length(trim(fields[i].asstring)) > 0) then

temp := formatdatetime('mm/dd/yyyy hh:nn:ss',fields[i].asdatetime)

else

temp := '01/01/2000 00:00:00'; //預設日期時間

end;

fttime:

begin

if (not fields[i].isnull) or

(length(trim(fields[i].asstring)) > 0) then

temp := formatdatetime('hh:nn:ss',fields[i].asdatetime)

else

temp := '00:00:00'; //預設時間

end;

end; //

end;

next;

end;   // eof

end;  // with

xmlstr:=doc.xml;

result:=1;

except

on e:exception do

result:=-1;

end;

end;

python生成xml格式檔案例項

本文是乙個python實現的生成xml格式檔案的操作例項,是非常常見的實用技巧,感興趣的朋友可以參考下 要生成的xml檔案格式如下 sample xml thing ma xiaoju springs widgets,inc.first i think widgets are greate.you ...

C C 解析XML格式檔案

前面我們講了生成xml檔案,但是 xml檔案怎麼解析呢?要解析的檔案 people mxmlloadfile null,rfp,mxml no callback 根標籤 object mxmlfindelement people,people,object null,null,mxml descen...

RapidJSON生成json格式檔案

json串 花括弧表示乙個 容器 方括號裝載陣列 名稱和值用冒號隔開 陣列元素通過逗號隔開 json示例 value是乙個陣列且裡面每個元素又是乙個json格式,string createjson 乙個陣列且裡面每個元素又是乙個json elp value array json karraytype...