XML文件读写示例
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了XML文件读写示例,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3965字,纯文字阅读大概需要6分钟。
内容图文
![XML文件读写示例](/upload/InfoBanner/zyjiaocheng/1239/feab4706ddb6454d881464b0884f3897.jpg)
写XML文件:
1 var 2 IXMLDoc : IXMLDocument; 3 XMLNode, xNodeItem: IXMLNode; 4 begin 5 IXMLDoc := NewXMLDocument(); 6try 7 XMLNode := IXMLDoc.AddChild(‘ConfigInfo‘); 8 9 xNodeItem := XMLNode.AddChild(‘VideoDB‘); 10 xNodeItem.Attributes[‘Host‘] := VideoSQLConfig.strAddress; 11 xNodeItem.Attributes[‘UserName‘] := VideoSQLConfig.strUserName; 12 xNodeItem.Attributes[‘PassWord‘] := VideoSQLConfig.strPassWord; 13 xNodeItem.Attributes[‘DBName‘] := VideoSQLConfig.strDBName; 141516 IXMLDoc.SaveToFile(strFileName); 17finally18 IXMLDoc := nil; 19end; 20end;
读取XML文件:
var IXMLDoc:IXMLDocument; xNodeRoot,xNodeItem:IXMLNode; nIndex: Integer; strNodeName: string ; begin if not FileExists(strFileName) then Exit; IXMLDoc := NewXMLDocument(); try IXMLDoc.LoadFromFile(strFileName); xNodeRoot := IXMLDoc.ChildNodes.Nodes[‘ConfigInfo‘]; for nIndex := 0to xNodeRoot.ChildNodes.Count - 1dobegin xNodeItem := xNodeRoot.ChildNodes[nIndex]; strNodeName := UpperCase(xNodeItem.NodeName); if strNodeName = UpperCase(‘VideoDB‘) thenbegin VideoSQLConfig.strAddress := xNodeItem.Attributes[‘Host‘]; VideoSQLConfig.strUserName := xNodeItem.Attributes[‘UserName‘]; VideoSQLConfig.strPassWord := xNodeItem.Attributes[‘PassWord‘]; VideoSQLConfig.strDBName := xNodeItem.Attributes[‘DBName‘]; Continue; end; end; finally IXMLDoc:=nil; end
var IXMLDoc : IXMLDocument; XMLNode, xNodeItem: IXMLNode;begin IXMLDoc := NewXMLDocument(); try XMLNode := IXMLDoc.AddChild(‘ConfigInfo‘);
xNodeItem := XMLNode.AddChild(‘VideoDB‘); xNodeItem.Attributes[‘Host‘] := VideoSQLConfig.strAddress; xNodeItem.Attributes[‘UserName‘] := VideoSQLConfig.strUserName; xNodeItem.Attributes[‘PassWord‘] := VideoSQLConfig.strPassWord; xNodeItem.Attributes[‘DBName‘] := VideoSQLConfig.strDBName;
xNodeItem := XMLNode.AddChild(‘VideoFTP‘); xNodeItem.Attributes[‘Host‘] := VideoFtpConfig.strHost; xNodeItem.Attributes[‘UserName‘] := VideoFtpConfig.strUserName; xNodeItem.Attributes[‘PassWord‘] := VideoFtpConfig.strPassWord; xNodeItem.Attributes[‘Dir‘] := VideoFtpConfig.strDir; xNodeItem.Attributes[‘Port‘] := IntToStr(VideoFtpConfig.nPort); if VideoFtpConfig.bPassive then xNodeItem.Attributes[‘Passive‘] := ‘1‘ else xNodeItem.Attributes[‘Passive‘] := ‘0‘; xNodeItem := XMLNode.AddChild(‘RecordFTP‘); xNodeItem.Attributes[‘Host‘] := RecordFTPConfig.strHost; xNodeItem.Attributes[‘UserName‘] := RecordFTPConfig.strUserName; xNodeItem.Attributes[‘PassWord‘] := RecordFTPConfig.strPassWord; xNodeItem.Attributes[‘Dir‘] := RecordFTPConfig.strDir; xNodeItem.Attributes[‘Port‘] := IntToStr(RecordFTPConfig.nPort); if RecordFTPConfig.bPassive then xNodeItem.Attributes[‘Passive‘] := ‘1‘ else xNodeItem.Attributes[‘Passive‘] := ‘0‘;
xNodeItem := XMLNode.AddChild(‘VideoServer‘); xNodeItem.Attributes[‘ServerUrl‘] := VideoServerUrl;
xNodeItem := XMLNode.AddChild(‘AudioServer‘); xNodeItem.Attributes[‘ServerUrl‘] := AudioServerUrl;
xNodeItem := XMLNode.AddChild(‘LKJ‘); xNodeItem.Attributes[‘LKJType‘] := IntToStr(Ord(LKJType));
xNodeItem.Attributes[‘Host‘] := LKJFTPConfig.strHost; xNodeItem.Attributes[‘UserName‘] := LKJFTPConfig.strUserName; xNodeItem.Attributes[‘PassWord‘] := LKJFTPConfig.strPassWord; xNodeItem.Attributes[‘Dir‘] := LKJFTPConfig.strDir; if LKJFTPConfig.bPassive then xNodeItem.Attributes[‘Passive‘] := ‘1‘ else xNodeItem.Attributes[‘Passive‘] := ‘0‘; xNodeItem.Attributes[‘SharePath‘] := LKJSharePath;
xNodeItem := XMLNode.AddChild(‘LKJSQL‘); xNodeItem.Attributes[‘Host‘] := LKJSQLConfig.strAddress; xNodeItem.Attributes[‘UserName‘] := LKJSQLConfig.strUserName; xNodeItem.Attributes[‘PassWord‘] := LKJSQLConfig.strPassWord; xNodeItem.Attributes[‘DBName‘] := LKJSQLConfig.strDBName;
xNodeItem := XMLNode.AddChild(‘LKJOracle‘); xNodeItem.Attributes[‘SvrName‘] := LKJOracleConfig.SvrName; xNodeItem.Attributes[‘User‘] := LKJOracleConfig.User; xNodeItem.Attributes[‘PWD‘] := LKJOracleConfig.PWD; IXMLDoc.SaveToFile(strFileName); finally IXMLDoc := nil; end;
原文:https://www.cnblogs.com/tsolarboy/p/9854567.html
内容总结
以上是互联网集市为您收集整理的XML文件读写示例全部内容,希望文章能够帮你解决XML文件读写示例所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。