Copy link to clipboard
Copied
Dear friends, experts and gurus!
Main purpose of my project FMfindRepl is saving the settings to an xml file and get them back later.
It turns out that 'roung-tripping' empty edit-fields is not handled correctly. It even leads to blocked functions (Buttons will not work any more).
<findstring></findstring>
<findstring></findstring>
are saved to the file as
<findstring/>
A crunch would be to postprocess the written xml file and replace all self-terminated elements by ordinary elements with start and end tags (see stackexchange).
<(\w+)/> → <$1></$1>
But I want to avoid writing these self-terminated elements directly.
→ How could this be achieved?
For the time being I decided to modifiy the written xml file with a function:
KLD_F.ConvertSelfTerminatedElements = function (xFile) { // ==========================
/* Expand self-terminating xml elements to empty start-tag end-tag elements
Arguments xFile xml file to be modified
Returns false in case of error, else true
Called by ButtonDelete, ButtonSave, ButtonSaveNew
Comment Self-terminating xml elements create problems when they are read.
...
Copy link to clipboard
Copied
For the time being I decided to modifiy the written xml file with a function:
KLD_F.ConvertSelfTerminatedElements = function (xFile) { // ==========================
/* Expand self-terminating xml elements to empty start-tag end-tag elements
Arguments xFile xml file to be modified
Returns false in case of error, else true
Called by ButtonDelete, ButtonSave, ButtonSaveNew
Comment Self-terminating xml elements create problems when they are read.
Buttons Retrieve, Save, SaveNew, Delete and Reset do not work any more.
Reference https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace
Used in FMfindRepl
History 2021-03-22
*/
var BOM = "\uFEFF", eReg1, eReg2, fXFile, xData;
function replacer (match, p1) {
return "<" + p1 + "></" + p1 + ">";
}
if ((xFile == null) || (xFile == undefined)) {
return false;
} else if (xFile.indexOf("/") > 0 || xFile.indexOf("\\") > 0) { // fully qualified path
fXFile = new File(xFile);
} else {
fXFile = new File($.fileName.replace (/[^\\\/]+$/i , xFile)); // file in script folder
}
if (fXFile.exists === false) {
KLD_F.Message ("E", KLD_F.UItxt.ConvertSelfTerminatedElements.@msg_01, "ConvertSelfTerminatedElements", sXmlFile, e.message);
return false;
}
fXFile.open("r");
xData = fXFile.read();
fXFile.close ();
xData = xData.replace (/<(\w+)\/>/g , replacer);
fXFile.open('w');
fXFile.encoding = "UTF-8";
fXFile.write(BOM);
fXFile.write(xData);
fXFile.close();
return true;
} //--- end ExpandSelfTerminatedElements -------------------------------------