关于TXMLDocument操纵xml的问题,为何添加节点不成功 ( 积分: 100 )

  • 主题发起人 Elite_liu
  • 开始时间
E

Elite_liu

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.Button1Click(Sender: TObject);
var
aNode, aValueNode: IXMLNode;
wStr: widestring;
begin
//+++++++++++++++++++++++++++++++++++++
//用TXmlDocument实现创建一个Xml文档
with XMLDocument1.XMLdo
begin
Add('<?xml version="1.0"
standalone="yes"?>');
Add('<ExportNew>');
Add('<savenight>');
Add('<name>savenight</name>');
Add('<sex>man</sex>');
Add('</savenight>');
Add('</ExportNew>');
end;
XMLDocument1.Active := true;
XMLDocument1.SaveToFile('d:/test.xml');
//下面是添加节点,但是没有添加进来为何?
aNode := XMLDocument1.DocumentElement.AddChild('stock');
aValueNode := aNode.AddChild('name');
aValueNode.Text := 'lhj';
aValueNode := aNode.AddChild('sex');
aValueNode.Text := 'man';
end;
 
procedure TForm1.Button1Click(Sender: TObject);
var
aNode, aValueNode: IXMLNode;
wStr: widestring;
begin
//+++++++++++++++++++++++++++++++++++++
//用TXmlDocument实现创建一个Xml文档
with XMLDocument1.XMLdo
begin
Add('<?xml version="1.0"
standalone="yes"?>');
Add('<ExportNew>');
Add('<savenight>');
Add('<name>savenight</name>');
Add('<sex>man</sex>');
Add('</savenight>');
Add('</ExportNew>');
end;
XMLDocument1.Active := true;
XMLDocument1.SaveToFile('d:/test.xml');
//下面是添加节点,但是没有添加进来为何?
aNode := XMLDocument1.DocumentElement.AddChild('stock');
aValueNode := aNode.AddChild('name');
aValueNode.Text := 'lhj';
aValueNode := aNode.AddChild('sex');
aValueNode.Text := 'man';
end;
 
把添加节点放在一个独立的按钮下执行也不能添加,为何?
procedure TForm1.Button2Click(Sender: TObject);
var
aNode, aValueNode: IXMLNode;
wStr: widestring;
begin
XMLDocument1.LoadFromFile('D:/test.xml');
XMLDOcument1.Active:=true;
aNode := XMLDocument1.DocumentElement.AddChild('stock');
aValueNode := aNode.AddChild('name');
aValueNode.Text := 'lhj';
aValueNode := aNode.AddChild('sex');
aValueNode.Text := 'man';
showmessage('sdfasdf');
end;
 
XMLDocument?的使用?
我想把access中数据写到.xml文件中,用程序实现。
通过网络传送到总公司,总公司那边 用XMLDocument控件显示数据
我在写到xml文件的时候,需要遵循什么格式才能让XMLDocument认出呢?设置XMLDocument的属性吗?
 
顶部