Forum > General

Change XML element names

(1/1)

SymbolicFrank:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---<?xml version="1.0" encoding="utf-8"?><CONFIG>  <TfrxReport>    <TfrxReportPage>..
should become:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---<?xml version="1.0" encoding="utf-8"?><CONFIG>  <LazReport>    <Pages>..
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?

jamie:
It seems you already know what to do..

I don't think it would be a good idea to rename nodes on the fly, most likely would cause some issues i am sure..


 Build a new DOC on the fly as you read the old one and change the names on the fly. It will be much faster and cleaner.

SymbolicFrank:
Thanks, I will. I already do that for the top node, because it's a new <CONFIG> one.

jollytall:
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:

--- Quote from: jollytall 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>?

--- End quote ---
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.

Navigation

[0] Message Index

Go to full version