procedure readXML(XMLPath : String)//XMLPath:XML文件路径 var XMLDoc : IXMLDocument; rNode : IXMLNode; pNode : IXMLNode; str1 : string; str2 : string; begin if (trim(XMLPath) = '') or (not FileExists(XMLPath)) then exit; CoInitialize(nil); XMLDoc := LoadXMLDocument(XMLPath); XMLDoc.FileName := XMLPath; XMLDoc.Active := True;
if XMLDoc.ChildNodes.First = nil then begin XMLDoc.Active := False; CoUnInitialize; exit; end; rNode := XMLDoc.DocumentElement; if rNode = nil then begin XMLDoc.Active := False; CoUnInitialize; exit; end else begin //XML文件内节点具体有几层,那要看实际中你定义的格式,这里只是一层 pNode := rNode.ChildNodes.First; while pNode <> Nil do begin str1 := pNode.Attributes['内容1'];//XML节点的属性值,这里只是示例说明 str2 := pNode.Attributes['内容2'];//XML节点的属性值,这里只是示例说明 pNode:= pNode.NextSibling; end; end; CoUnInitialize; end; 服务端写一个服务端程序,客户端通过TClientSocket与服务端的TServerSocket连接,发消息给服务端,消息是自定义的,服务端接收到指定的消息,检测然后生成XML文件,把文件传送给客户端,客户端可以用上面介绍的函数(要自己修改成服务器端XML文件格式)。一般说服务器端要有个驻留内存的程序用来接收客户端的消息的程序。至于写XML文件,把上面的函数稍微改动一下就可以了。
var
XMLDoc : IXMLDocument;
rNode : IXMLNode;
pNode : IXMLNode;
str1 : string;
str2 : string;
begin
if (trim(XMLPath) = '') or (not FileExists(XMLPath)) then
exit; CoInitialize(nil);
XMLDoc := LoadXMLDocument(XMLPath);
XMLDoc.FileName := XMLPath;
XMLDoc.Active := True;
if XMLDoc.ChildNodes.First = nil then
begin
XMLDoc.Active := False;
CoUnInitialize;
exit;
end; rNode := XMLDoc.DocumentElement; if rNode = nil then
begin
XMLDoc.Active := False;
CoUnInitialize;
exit;
end
else
begin
//XML文件内节点具体有几层,那要看实际中你定义的格式,这里只是一层
pNode := rNode.ChildNodes.First;
while pNode <> Nil do
begin
str1 := pNode.Attributes['内容1'];//XML节点的属性值,这里只是示例说明
str2 := pNode.Attributes['内容2'];//XML节点的属性值,这里只是示例说明 pNode:= pNode.NextSibling;
end;
end;
CoUnInitialize;
end;
服务端写一个服务端程序,客户端通过TClientSocket与服务端的TServerSocket连接,发消息给服务端,消息是自定义的,服务端接收到指定的消息,检测然后生成XML文件,把文件传送给客户端,客户端可以用上面介绍的函数(要自己修改成服务器端XML文件格式)。一般说服务器端要有个驻留内存的程序用来接收客户端的消息的程序。至于写XML文件,把上面的函数稍微改动一下就可以了。
上面有很专业很详细的讲解...
http://princed.mblogger.cn/category/776.aspx