He conseguido leer dos niveles de profuncidad del XML, pero me falla al leer las direcciones del 2º contacto, alguien me puede ayudar, me falta una linea al salir del repeat de las direcciones.
Código Delphi
[-]
procedure TForm1.btnRefreshClick(Sender: TObject);
var
NContacto, NDireccion: IXMLNode;
begin
XMLDoc.FileName := 'c:\ejemplo.xml';
XMLDoc.Active:=True;
NContacto := XMLDoc.DocumentElement.ChildNodes.FindNode('contacto');
NDireccion := XMLDoc.DocumentElement.ChildNodes.First.ChildNodes.FindNode('dir');
repeat
LB1.Items.Add(NContacto.ChildNodes['nombre'].Text);
LB1.Items.Add(NContacto.ChildNodes['direccion'].Text);
LB1.Items.Add(NContacto.ChildNodes['telf'].Text);
repeat
LB1.Items.Add(NDireccion.ChildNodes['nombre'].Text);
LB1.Items.Add(NDireccion.ChildNodes['direccion'].Text);
LB1.Items.Add(NDireccion.ChildNodes['telf'].Text);
NDireccion := NDireccion.NextSibling;
Until NDireccion = nil;
NContacto := NContacto.NextSibling;
Until NContacto = nil;
end;
El codigo del XML que uso de prueba:
Código:
<?xml version="1.0" encoding="iso-8859-1"?>
<copia>
<contacto>
<nombre>NomCon 1</nombre>
<direccion>DirCon 1</direccion>
<telf>TelfCon 1</telf>
<dir>
<nombre>Nom 1</nombre>
<direccion>Dir 1</direccion>
<telf>Telf 1</telf>
</dir>
<dir>
<nombre>Nom 2</nombre>
<direccion>Dir 2</direccion>
<telf>telf 2</telf>
</dir>
</contacto>
<contacto>
<nombre>NomCon 2</nombre>
<direccion>DirCon 2</direccion>
<telf>TelfCon 2</telf>
<dir>
<nombre>Nom 3</nombre>
<direccion>Dir 3</direccion>
<telf>telf 3</telf>
</dir>
<dir>
<nombre>Nom 4</nombre>
<direccion>Dir 4</direccion>
<telf>Telf 4</telf>
</dir>
</contacto>
</copia>
A ver si postea alguien que no creo que sea el unico que se atreve con el XML.
Un saludo y gracias.