var XMLDoc : IXMLDOMDocument ;
Root : IXMLDOMElement ;
Node : IXMLDOMNode ;
Attributes : IXMLDOMNamedNodeMap ;
i , Len: integer ;
Method : String ;
Name : String ;
Password : String ;
begin
//Memo1.Lines.Add(Socket.ReceiveText);
XMLDoc := CoDomDocument.Create ;
XMLDoc.async := False ;
XMLDoc.load('E:\delphi\bank\xml\login.xml');
Root := XMLDoc.documentElement ;
Attributes := Root.firstChild.attributes;
出错就在Attributes READ 000000
有没有例子呀,我的
XML:
<?xml version="1.0" encoding ="gb2312" ?>
<!DOCTYPE logininformation [
<!ELEMENT login (name,password)>
]>
<login>
<name>james</name>
<password>111</password>
</login>
Root : IXMLDOMElement ;
Node : IXMLDOMNode ;
Attributes : IXMLDOMNamedNodeMap ;
i , Len: integer ;
Method : String ;
Name : String ;
Password : String ;
begin
//Memo1.Lines.Add(Socket.ReceiveText);
XMLDoc := CoDomDocument.Create ;
XMLDoc.async := False ;
XMLDoc.load('E:\delphi\bank\xml\login.xml');
Root := XMLDoc.documentElement ;
Attributes := Root.firstChild.attributes;
出错就在Attributes READ 000000
有没有例子呀,我的
XML:
<?xml version="1.0" encoding ="gb2312" ?>
<!DOCTYPE logininformation [
<!ELEMENT login (name,password)>
]>
<login>
<name>james</name>
<password>111</password>
</login>
****************************************************
<?xml version="1.0"?>
<node1>
<node1 value="value1" color="color1" bgcolor="bgcolor1"/>
</node1>****************************************************
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, xmldom, XMLIntf, msxmldom, XMLDoc, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
XMLDocument1: TXMLDocument;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
i:integer;
implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
// BC,C: olevariant;
//h:longint;
xn:IXMLNode;
xm:IXMLNode;
t:integer;
j:integer;
begin
xmldocument1.Active:=true;
xn:=XMLDocument1.DocumentElement;
//显示节点的内容
edit1.Text:=xn.ChildNodes.Nodes[0].Attributes['color'];
//*******************************
//克隆一条记录,并且删除克隆体
xm:=xn.ChildNodes.Nodes[0];
xn.ChildNodes.Delete(0);
//添加三行数据到xml文件去
for j:=1 to 3 do
begin
{//**********
//通过节点的索引访问
t:=XMLDocument1.DocumentElement.ChildNodes.Add(xm.CloneNode(true));
//showmessage(inttostr(t));
xn.ChildNodes.Nodes[t].Attributes['value']:='value'+inttostr(t);
xn.ChildNodes.Nodes[t].Attributes['color']:='color'+inttostr(t);
xn.ChildNodes.Nodes[t].Attributes['bgcolor']:='bgcolor'+inttostr(t);
}
//***********
//通过节点直接访问
xm:=xn.AddChild('node'+inttostr(i));
xm.Attributes['value']:='value'+inttostr(i);
xm.Attributes['color']:='color'+inttostr(i);
xm.Attributes['bgcolor']:='bgcolor'+inttostr(i);
inc(i);
end; xmldocument1.SaveToFile('D:\我的delphi例子\12\pos.xml');
xmldocument1.Active:=false;
//-----------------------
//richedit1.Lines.Append(edit1.Text);
end;procedure TForm1.FormCreate(Sender: TObject);
begin
i:=1;
end;end.
http://www.csdn.net/develop/read_article.asp?id=12428
会对你有帮助的