¿Cómo elimino registros XML desde Delphi 7?
Publicado por Nancy Paola (2 intervenciones) el 13/12/2007 18:51:16
Ayuda porfavor, necesito eliminar registros, pero no se cómo, sólo puedo realizar altas, y este es el código, funciona a la perfeccion las altas. Pero ayudenme porfavor con la eliminación....... ¿siiiiiiiiii....?
unit UFRMcaptura;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, XMLdoc, XMLIntf, xmldom;
type
TFRMcaptura_datos = class(TForm)
Label1: TLabel;
Label2: TLabel;
TXTnombre: TEdit;
TXTtelefono: TEdit;
BTNok: TButton;
BTNcancel: TButton;
procedure BTNcancelClick(Sender: TObject);
procedure BTNokClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FRMcaptura_datos: TFRMcaptura_datos;
implementation
{$R *.dfm}
procedure TFRMcaptura_datos.BTNcancelClick(Sender: TObject);
begin
self.Close;
end;
procedure TFRMcaptura_datos.BTNokClick(Sender: TObject);
Var
XMLOwner : TDataModule;
mXML : TXMLDocument;
nodo_Directorio : IXMLNode;
nodo_Contacto : IXMLNode;
begin
XMLOwner := TDataModule.Create(nil);
mXML := TXMLDocument.Create(XMLOwner);
mxml.Active:=true;
//Verificar si existe el archivo
if FileExists('agenda.xml') then
begin
//Recuperar los datos ya guardados
mxml.LoadFromFile('agenda.xml');
nodo_directorio:=mxml.DocumentElement;
end
else
Begin
//si no existe, crea el arbol XML
nodo_directorio:=mxml.CreateElement('directorio','mi_XML');
End;
//Añadir un contacto en el arbol al inicio de la lista
nodo_directorio.AddChild('contacto',0);
//Añadir los componentes del contacto (nombre, telefono)
nodo_contacto:=nodo_directorio.ChildNodes.First;
nodo_contacto.AddChild('nombre',0);
nodo_contacto.ChildNodes[0].Text:=self.TXTnombre.Text;
nodo_contacto.AddChild('telefono',1);
nodo_contacto.ChildNodes[1].Text:=self.TXTtelefono.Text;
//Guarda el arbol XML (directorio) en un archivo (agenda.XML)
mxml.DocumentElement:=nodo_directorio;
mXML.SaveToFile('agenda.xml');
showmessage('Contacto agregado');
self.Close;
end;
end.
unit UFRMcaptura;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, XMLdoc, XMLIntf, xmldom;
type
TFRMcaptura_datos = class(TForm)
Label1: TLabel;
Label2: TLabel;
TXTnombre: TEdit;
TXTtelefono: TEdit;
BTNok: TButton;
BTNcancel: TButton;
procedure BTNcancelClick(Sender: TObject);
procedure BTNokClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FRMcaptura_datos: TFRMcaptura_datos;
implementation
{$R *.dfm}
procedure TFRMcaptura_datos.BTNcancelClick(Sender: TObject);
begin
self.Close;
end;
procedure TFRMcaptura_datos.BTNokClick(Sender: TObject);
Var
XMLOwner : TDataModule;
mXML : TXMLDocument;
nodo_Directorio : IXMLNode;
nodo_Contacto : IXMLNode;
begin
XMLOwner := TDataModule.Create(nil);
mXML := TXMLDocument.Create(XMLOwner);
mxml.Active:=true;
//Verificar si existe el archivo
if FileExists('agenda.xml') then
begin
//Recuperar los datos ya guardados
mxml.LoadFromFile('agenda.xml');
nodo_directorio:=mxml.DocumentElement;
end
else
Begin
//si no existe, crea el arbol XML
nodo_directorio:=mxml.CreateElement('directorio','mi_XML');
End;
//Añadir un contacto en el arbol al inicio de la lista
nodo_directorio.AddChild('contacto',0);
//Añadir los componentes del contacto (nombre, telefono)
nodo_contacto:=nodo_directorio.ChildNodes.First;
nodo_contacto.AddChild('nombre',0);
nodo_contacto.ChildNodes[0].Text:=self.TXTnombre.Text;
nodo_contacto.AddChild('telefono',1);
nodo_contacto.ChildNodes[1].Text:=self.TXTtelefono.Text;
//Guarda el arbol XML (directorio) en un archivo (agenda.XML)
mxml.DocumentElement:=nodo_directorio;
mXML.SaveToFile('agenda.xml');
showmessage('Contacto agregado');
self.Close;
end;
end.
Valora esta pregunta


0