Recent

Author Topic: How to delete all children of node in XML?  (Read 5224 times)

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
How to delete all children of node in XML?
« on: July 26, 2014, 08:01:47 pm »
Hi,
how to delete all children of node in TXMLDocument? I cannot see any method for it there.
There's only:
Code: [Select]
function RemoveChild(OldChild: TDOMNode): TDOMNode;it seems it's not it.

EDIT: I forgot, it's about units Laz2_XMLRead, Laz2_XMLWrite and Laz2_DOM.
« Last Edit: July 26, 2014, 08:29:29 pm by Blaazen »
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: How to delete all children of node in XML?
« Reply #1 on: July 26, 2014, 09:19:35 pm »
OK, this works:
Code: [Select]
  aDeviceNode:=ASectionNode.FirstChild;
  while assigned(aDeviceNode) do
    begin
      aNode:=aDeviceNode;
      aDeviceNode:=aDeviceNode.NextSibling;         
      ASectionNode.RemoveChild(aNode);       
    end;
This removes all children nodes in ASectionNode.
Maybe it's possible to do it simplier (without aNode variable.), but I don't understand exactly what OldChild means and what value that function return.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

benohb

  • Full Member
  • ***
  • Posts: 213
Re: How to delete all children of node in XML?
« Reply #2 on: July 27, 2014, 05:50:13 am »
Thank you for the information  :D

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: How to delete all children of node in XML?
« Reply #3 on: July 27, 2014, 09:46:08 am »
There can be added one line:
Code: [Select]
  aDeviceNode:=ASectionNode.FirstChild;
  while assigned(aDeviceNode) do
    begin
      aNode:=aDeviceNode;
      aDeviceNode:=aDeviceNode.NextSibling;         
      aNode:=ASectionNode.RemoveChild(aNode);   //modified   
      aNode.Free;   //added
    end;
Function RemoveChild() removes child-node from the parent node (but it does not delete it) and returns reference to this node, which is now stand-alone.
Line aNode.Free deletes this node immediately; otherwise it is freed when whole XMLDocument is freed (it is Owner of all nodes).
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

 

TinyPortal © 2005-2018