• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Delphi7生成XML

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

文件格式为:

Day	制1課	U12	ASSY01	Wrist	1009	0	2018/05/18 09:35:59
Day	制1課	U12	ASSY02	Wrist	1010	0	2018/05/18 09:36:01
Day	制1課	U12	ASSY03	Wrist	1011	0	2018/05/18 09:36:03
Day	制1課	U12	ASSY04	Wrist	1012	0	2018/05/18 09:36:05
Day	制1課	U12	ASSY05	Wrist	1013	0	2018/05/18 09:36:07
Day	制1課	U12	ASSY06	Wrist	1014	0	2018/05/18 09:36:10
Day	制1課	U12	ASSY07	Wrist	1015	0	2018/05/18 09:36:12
Day	制1課	U12	ASSY08	Wrist	1016	0	2018/05/18 09:36:14
Day	制1課	U12	ASSY09	Wrist	1017	0	2018/05/18 09:36:16

2.把此文件转成XML(用Delphi7):

procedure TForm1.Button1Click(Sender: TObject);
var
  lst,lstfield :TStringList;
  xml:TXMLDocument;
  node :IXMLNode;
  i,j:integer;
begin
  xml := TXMLDocument.Create(nil);
  try
    xml.Active := True;
    xml.Version := '1.0';
    xml.Encoding := 'UTF-8';
    xml.DocumentElement := xml.CreateElement('ESDDATA','ESD');
    xml.Options:=[doNodeAutoIndent];
    xml.NodeIndentStr :=#9;
    lstfield := TStringList.Create;
    try
      lst := TStringList.Create;
      try
        lst.LoadFromFile('ESDStatus.txt');
        Memo1.Text := lst.Text;
        for i:=0 to lst.Count-1 do
        begin
          lstfield.Clear;

          ExtractStrings([Char(VK_TAB)],[' '], PChar(lst[i]), lstfield) ;

          if lstfield.Count>0 then
          begin
             node := xml.DocumentElement.AddChild('item');
             {node.AddChild('SHIFT_NAME').Text :=lstfield[0];   --加子元素
             node.AddChild('PRODUCT_ROOM').Text :=lstfield[1];
             node.AddChild('PDLINE_NAME').Text :=lstfield[2];
             node.AddChild('POSITION').Text :=lstfield[3];
             node.AddChild('CATEGORY').Text :=lstfield[4];
             node.AddChild('NO').Text :=lstfield[5];
             node.AddChild('STATUS').Text :=lstfield[6];
             node.AddChild('PROCESSTIME').Text :=lstfield[7];}
             node.Attributes['SHIFT_NAME']:= lstfield[0];  //增加元素属性
             node.Attributes['PRODUCT_ROOM']:= lstfield[1];
             node.Attributes['PDLINE_NAME']:= lstfield[2];
             node.Attributes['POSITION']:= lstfield[3];
             node.Attributes['CATEGORY']:= lstfield[4];
             node.Attributes['NO']:= lstfield[5];
             node.Attributes['STATUS']:= lstfield[6];
             node.Attributes['PROCESSTIME']:= lstfield[7];
          end;
        end;
      finally
        lst.Free;
      end;
    finally
      lstfield.Free;
    end;
    Memo2.Lines.Text:= xml.XML.Text;
  finally
    node:=nil;
    xml.Active := false;
    xml.Free;
  end;

end;

3 生成子元素的内容为:

<?xml version="1.0" encoding="UTF-8"?>
<ESDDATA xmlns="ESD">
    <item>
        <SHIFT_NAME>Day</SHIFT_NAME>
        <PRODUCT_ROOM>鍒?瑾?/PRODUCT_ROOM>
        <PDLINE_NAME>U12</PDLINE_NAME>
        <POSITION>ASSY01</POSITION>
        <CATEGORY>Wrist</CATEGORY>
        <NO>1009</NO>
        <STATUS>0</STATUS>
        <PROCESSTIME>2018/05/18 09:35:59</PROCESSTIME>
    </item>
    <item>
        <SHIFT_NAME>Day</SHIFT_NAME>
        <PRODUCT_ROOM>鍒?瑾?/PRODUCT_ROOM>
        <PDLINE_NAME>U12</PDLINE_NAME>
        <POSITION>ASSY02</POSITION>
        <CATEGORY>Wrist</CATEGORY>
        <NO>1010</NO>
        <STATUS>0</STATUS>
        <PROCESSTIME>2018/05/18 09:36:01</PROCESSTIME>
    </item>
    <item>
        <SHIFT_NAME>Day</SHIFT_NAME>
        <PRODUCT_ROOM>鍒?瑾?/PRODUCT_ROOM>
        <PDLINE_NAME>U12</PDLINE_NAME>
        <POSITION>ASSY03</POSITION>
        <CATEGORY>Wrist</CATEGORY>
        <NO>1011</NO>
        <STATUS>0</STATUS>
        <PROCESSTIME>2018/05/18 09:36:03</PROCESSTIME>
    </item>
    <item>
        <SHIFT_NAME>Day</SHIFT_NAME>
        <PRODUCT_ROOM>鍒?瑾?/PRODUCT_ROOM>
        <PDLINE_NAME>U12</PDLINE_NAME>
        <POSITION>ASSY04</POSITION>
        <CATEGORY>Wrist</CATEGORY>
        <NO>1012</NO>
        <STATUS>0</STATUS>
        <PROCESSTIME>2018/05/18 09:36:05</PROCESSTIME>
    </item>
    <item>
        <SHIFT_NAME>Day</SHIFT_NAME>
        <PRODUCT_ROOM>鍒?瑾?/PRODUCT_ROOM>
        <PDLINE_NAME>U12</PDLINE_NAME>
        <POSITION>ASSY05</POSITION>
        <CATEGORY>Wrist</CATEGORY>
        <NO>1013</NO>
        <STATUS>0</STATUS>
        <PROCESSTIME>2018/05/18 09:36:07</PROCESSTIME>
    </item>
    <item>
        <SHIFT_NAME>Day</SHIFT_NAME>
        <PRODUCT_ROOM>鍒?瑾?/PRODUCT_ROOM>
        <PDLINE_NAME>U12</PDLINE_NAME>
        <POSITION>ASSY06</POSITION>
        <CATEGORY>Wrist</CATEGORY>
        <NO>1014</NO>
        <STATUS>0</STATUS>
        <PROCESSTIME>2018/05/18 09:36:10</PROCESSTIME>
    </item>
    <item>
        <SHIFT_NAME>Day</SHIFT_NAME>
        <PRODUCT_ROOM>鍒?瑾?/PRODUCT_ROOM>
        <PDLINE_NAME>U12</PDLINE_NAME>
        <POSITION>ASSY07</POSITION>
        <CATEGORY>Wrist</CATEGORY>
        <NO>1015</NO>
        <STATUS>0</STATUS>
        <PROCESSTIME>2018/05/18 09:36:12</PROCESSTIME>
    </item>
    <item>
        <SHIFT_NAME>Day</SHIFT_NAME>
        <PRODUCT_ROOM>鍒?瑾?/PRODUCT_ROOM>
        <PDLINE_NAME>U12</PDLINE_NAME>
        <POSITION>ASSY08</POSITION>
        <CATEGORY>Wrist</CATEGORY>
        <NO>1016</NO>
        <STATUS>0</STATUS>
        <PROCESSTIME>2018/05/18 09:36:14</PROCESSTIME>
    </item>
    <item>
        <SHIFT_NAME>Day</SHIFT_NAME>
        <PRODUCT_ROOM>鍒?瑾?/PRODUCT_ROOM>
        <PDLINE_NAME>U12</PDLINE_NAME>
        <POSITION>ASSY09</POSITION>
        <CATEGORY>Wrist</CATEGORY>
        <NO>1017</NO>
        <STATUS>0</STATUS>
        <PROCESSTIME>2018/05/18 09:36:16</PROCESSTIME>
    </item>
</ESDDATA>

 

4 生成元素属性内容为:

<?xml version="1.0" encoding="UTF-8"?>
<ESDDATA xmlns="ESD">
    <item SHIFT_NAME="Day" PRODUCT_ROOM="鍒?瑾? PDLINE_NAME="U12" POSITION="ASSY01" CATEGORY="Wrist" NO="1009" STATUS="0" PROCESSTIME="2018/05/18 09:35:59"/>
    <item SHIFT_NAME="Day" PRODUCT_ROOM="鍒?瑾? PDLINE_NAME="U12" POSITION="ASSY02" CATEGORY="Wrist" NO="1010" STATUS="0" PROCESSTIME="2018/05/18 09:36:01"/>
    <item SHIFT_NAME="Day" PRODUCT_ROOM="鍒?瑾? PDLINE_NAME="U12" POSITION="ASSY03" CATEGORY="Wrist" NO="1011" STATUS="0" PROCESSTIME="2018/05/18 09:36:03"/>
    <item SHIFT_NAME="Day" PRODUCT_ROOM="鍒?瑾? PDLINE_NAME="U12" POSITION="ASSY04" CATEGORY="Wrist" NO="1012" STATUS="0" PROCESSTIME="2018/05/18 09:36:05"/>
    <item SHIFT_NAME="Day" PRODUCT_ROOM="鍒?瑾? PDLINE_NAME="U12" POSITION="ASSY05" CATEGORY="Wrist" NO="1013" STATUS="0" PROCESSTIME="2018/05/18 09:36:07"/>
    <item SHIFT_NAME="Day" PRODUCT_ROOM="鍒?瑾? PDLINE_NAME="U12" POSITION="ASSY06" CATEGORY="Wrist" NO="1014" STATUS="0" PROCESSTIME="2018/05/18 09:36:10"/>
    <item SHIFT_NAME="Day" PRODUCT_ROOM="鍒?瑾? PDLINE_NAME="U12" POSITION="ASSY07" CATEGORY="Wrist" NO="1015" STATUS="0" PROCESSTIME="2018/05/18 09:36:12"/>
    <item SHIFT_NAME="Day" PRODUCT_ROOM="鍒?瑾? PDLINE_NAME="U12" POSITION="ASSY08" CATEGORY="Wrist" NO="1016" STATUS="0" PROCESSTIME="2018/05/18 09:36:14"/>
    <item SHIFT_NAME="Day" PRODUCT_ROOM="鍒?瑾? PDLINE_NAME="U12" POSITION="ASSY09" CATEGORY="Wrist" NO="1017" STATUS="0" PROCESSTIME="2018/05/18 09:36:16"/>
</ESDDATA>

 

5:可以把以上的内容做为参数传给数据库进行处理,保证事物的原子性(具休调用待后续提供).


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
(转)Delphi读写UTF-8、Unicode格式文本文件发布时间:2022-07-18
下一篇:
Delphi用ini文档实现界面无闪烁多语言转换发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap