begin
// XMLDocument1.LoadFromFile(PathString(AppPath)+'wangp.xml');
XmlFile:=ExtractFileName(Application.ExeName+'\wangp.xml');
XmlDocument1.FileName:=XmlFile;
XMLDocument1.Active:=true;
add;
end;
procedure TForm1.add;
var Node:IXMLNode;
NodeList:IXMLNodeList;
i,m,j:Integer;
lst:TListItem;
begin
ListView1.Items.Clear;
Node:=XMLDocument1.DocumentElement;//
ListView1.Items.BeginUpdate;
NodeList:=Node.ChildNodes;
for i:=0 to NodeList.Count-1 do
begin
lst:=ListView1.Items.Add;
Node:=NodeList.Nodes[i].ChildNodes.Nodes[0];
lst.Caption:='';
for j:=0 to NodeList.Nodes[i].ChildNodes.Count-1 do
begin
lst.SubItems.Add(NodeList.Nodes[i].ChildNodes.Nodes[j].GetText());
end;
lst.ImageIndex:=0;
end;
ListView1.Items.EndUpdate;
Node:=XMLDocument1.CreateElement('price','pri');
Node.
end;
procedure TForm1.AddFromQuery(id,name,cha:string);
var Node,SubNode:IXMLNode;
begin
Node:=XMLDocument1.DocumentElement;
Node:=Node.AddChild(WideString('Tip'));
SubNode:=Node.AddChild(WideString('userid'));
SubNode.SetText(id);
SubNode:=Node.AddChild(WideString('name'));
SubNode.SetText(name);
SubNode:=Node.AddChild(WideString('cha'));
SubNode.SetText(cha);
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
var userid,name,cha:string;
begin
// AddFromQuery('wangp','slfj','22222.00');
AdoQuery1.Close;
AdoQuery1.Parameters.ParamByName('set').Value:='21101';
AdoQuery1.Open;
while not AdoQuery1.Eof do
begin
userid:=AdoQuery1.FieldByName('User_id').AsString;
name:=AdoQuery1.FieldByName('User_name').AsString;
cha:=AdoQuery1.FieldByName('total_cha').AsString;
AddFromQuery(userid,name,cha);
AdoQuery1.Next;
end;
XMLDocument1.SaveToFile(XMlFile);
BitBtn1Click(self);
end;
procedure TForm1.BitBtn3Click(Sender: TObject);
var Node:IXMLNode;
i:Integer;
begin
i:=ListView1.Selected.Index;
Node:=XMLDocument1.DocumentElement;
Node.ChildNodes.Delete(i);
ListView1.Items.Delete(i);
XMLDocument1.SaveToFile(XMlFile);
function TArrayWithXML.GetValue: WideString;
begin
result := self.myxmldoc.XML.Text;
end;
function TArrayWithXML.GetNodeCount: Integer;
begin
result := myxmlnode.ChildNodes.Count;
end;
destructor TArrayWithXML.Destroy;
begin
Owner.Free;
inherited;
end;
constructor TArrayWithXML.Create;
begin
inherited;
Owner := TComponent.Create(nil);
self.myxmldoc := Txmldocument.Create(self.Owner);
with myxmldoc.XML do
begin
add('<?xml version="1.0" encoding="gb2312"?>');
add('<VariantArray></VariantArray>');
end;
myxmldoc.Active := true;
myxmlnode := myxmldoc.DocumentElement;
end;
procedure TArrayWithXML.Clear;
begin
self.myxmldoc.XML.Clear;
with myxmldoc.XML do
begin
add('<?xml version="1.0" encoding="gb2312"?>');
add('<VariantArray></VariantArray>');
end;
myxmldoc.Active := true;
myxmlnode := myxmldoc.DocumentElement;
end;