How can I traverse an XML node to node

0

I have the following XML:

<?xml version="1.0"?>
<tv generator-info-name="Panel IPTV" generator-info url="http://tvla.xyz:25461/">
    <channel id="AandE.mx">
        <display-name>A&amp;E [0]</display-name>
        <icon src="http://www.chileiptv.xyz/logos/153.jpg"/>
    </channel>
    <channel id="AXN.mx">
        <display-name>AXN [0]</display-name>
        <icon src="http://www.chileiptv.xyz/logos/157.jpg"/>
    </channel>
    <channel id="AztecaCinema.mx">
        <display-name>Azteca Cinema HD [0]</display-name>
        <icon src="http://www.chileiptv.xyz/logos/158.jpg"/>
    </channel>
    <channel id="Azteca13.mx">
        <display-name>Azteca 13 [0]</display-name>
        <icon src="http://www.chileiptv.xyz/logos/22.jpg"/>
    </channel>
    <channel id="Azteca7.mx">
        <display-name>Azteca 7 [0]</display-name>
        <icon src="http://www.chileiptv.xyz/logos/23.jpg"/>
    </channel>
</tv>

I do the route of the nodes with the following routine:

var
  StartItemNode, item: IXMLNode;
  id: string;
begin
  uqChannels.Close;
  uqProgramacion.Close;
  try
    usVaciarProgramacion.Execute;
    if XMLDoc.DocumentElement.NodeName = 'tv' then
    begin
      StartItemNode := XMLDoc.DocumentElement.ChildNodes.FindNode('channel');
      item := StartItemNode;
      while item.NodeName = 'channel' do
      begin
        id := item.Attributes['id'];
        item.NextSibling;
      end;
    end;
  finally
    uqChannels.Open;
    uqProgramacion.Open;
  end;
end;

But the route does not leave the first node.

    
asked by Miguel Molina 26.04.2018 в 15:06
source

1 answer

0

To be able to perform the iteration on the "brother" you must recover the value

item := item.NextSibling;

When doing this, item retrieves the value of the next node. With this, the following nodes come to you. But keep in mind that in the end item will not be assigned when there are no more nodes. So in the loop you have to make sure it is assigned. It would look like this:

while assigned(item) and (item.NodeName = 'channel') do
begin
    id := item.Attributes['id'];
    //¿No habría que hacer algo on id?
    item := item.NextSibling;
end;

I hope it serves you

    
answered by 27.04.2018 в 09:16