Recent

Author Topic: XML: TDOMNode.AddChild  (Read 7457 times)

stocki

  • Full Member
  • ***
  • Posts: 144
XML: TDOMNode.AddChild
« on: February 03, 2013, 08:38:55 pm »
Does anyone know how to implement that?

unit DOM;

function TDOMNode.AddChild(AName: DOMString): TDOMNode;
begin
  ???
end;


Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: XML: TDOMNode.AddChild
« Reply #1 on: February 04, 2013, 12:35:10 am »
You have to create element and then append it.
I have written a very small unit for xml configuration files, I have there this:
Code: [Select]
procedure TXMLCfgDoc.FindOrCreateSection(ASection: string);
begin
  SectionNode:=DocumentElement.FindNode(ASection);
  if not assigned(SectionNode) then
    begin
      SectionNode:=CreateElement(ASection);
      DocumentElement.AppendChild(SectionNode);
    end;
end;
You can see that it firstly search if node already exists. If no, it creates it.
(Note that my code is only two or three levels).
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/

stocki

  • Full Member
  • ***
  • Posts: 144
Re: XML: TDOMNode.AddChild
« Reply #2 on: February 16, 2013, 10:46:20 am »
Thank you for the reply. But your solution is not Delphi/TXMLDocument compatible. Only FPC compatible. A problem for me.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: XML: TDOMNode.AddChild
« Reply #3 on: February 16, 2013, 01:53:32 pm »
The solution, of course, is to also use the FPC units under Delphi.

I did so in 2008, but that is before Sergei started to work on them (and the old ones are quite decrepit). Have to refresh them someday.

stocki

  • Full Member
  • ***
  • Posts: 144
Re: XML: TDOMNode.AddChild
« Reply #4 on: February 16, 2013, 03:25:02 pm »
I am looking for a solution where I can replace different XML solution without changing the program code (>10k of lines). A common interface would be a first step.

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: XML: TDOMNode.AddChild
« Reply #5 on: February 16, 2013, 04:34:07 pm »
Hi stocki,

I'm developing a new approach to write and read XML, see here:

http://www.lazarus.freepascal.org/index.php/topic,19717.msg113830.html#msg113830

any doubts, I can help.

Thanks.
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

stocki

  • Full Member
  • ***
  • Posts: 144
Re: XML: TDOMNode.AddChild
« Reply #6 on: February 16, 2013, 08:20:39 pm »
The approach is good. But it should use the same names as exposed in TXMLNode/TXMLDocument from Delphi.

Hi stocki,

I'm developing a new approach to write and read XML, see here:

http://www.lazarus.freepascal.org/index.php/topic,19717.msg113830.html#msg113830

any doubts, I can help.

Thanks.

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: XML: TDOMNode.AddChild
« Reply #7 on: February 17, 2013, 04:22:30 pm »
See comment from Marcov:
"The solution, of course, is to also use the FPC units under Delphi."  ;D

One question: the Delphi TXMLDocument implementation are  compatible for all Delphi versions?

Thank you.

Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

 

TinyPortal © 2005-2018