Recent

Author Topic: Change XML element names  (Read 4113 times)

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Change XML element names
« on: November 29, 2021, 12:19:26 pm »
I have a bunch of XML files that have to be converted. (From FastReport 3 to LazReport.) Which includes: changing the names of much of the elements.

Code: Pascal  [Select][+][-]
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <CONFIG>
  3.   <TfrxReport>
  4.     <TfrxReportPage>
  5. ..

should become:

Code: Pascal  [Select][+][-]
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <CONFIG>
  3.   <LazReport>
  4.     <Pages>
  5. ..

But TDOMNode.NodeName isn't writable. I could make a new node with the right name, add all the child nodes to it and replace the old one with the new one. Or perhaps add a SetNodeName method. But there is probably a simpler way?

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: Change XML element names
« Reply #1 on: November 29, 2021, 03:52:31 pm »
Thanks, I will. I already do that for the top node, because it's a new <CONFIG> one.

jollytall

  • Sr. Member
  • ****
  • Posts: 306
Re: Change XML element names
« Reply #2 on: November 29, 2021, 04:30:21 pm »
Probably too simple, but what stops you reading it as a text and change the name of the elements with simple string change? Why do you have to "know" that it is an XML doc to change e.g. a <TfrxReport> substring to <LazReport>?

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: Change XML element names
« Reply #3 on: November 29, 2021, 07:08:00 pm »
Probably too simple, but what stops you reading it as a text and change the name of the elements with simple string change? Why do you have to "know" that it is an XML doc to change e.g. a <TfrxReport> substring to <LazReport>?
Yes, I have thought about that as well, but when I change the element name, I have to add a new child element with "ClassName=OldName". Doing that in a string seemed too much work.

Btw, the XML format of both FastReport and LazReport is strange. It probably started with Delphi streaming the published properties of the controls to XML, but I don't know how that file looked and I didn't try that with Lazarus so far.

 

TinyPortal © 2005-2018