Community Expert
March 22, 2021
Answered
Self closing xml elements considered harmful
- March 22, 2021
- 1 reply
- 386 views
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).
- Field "find what" is empty for various find operations, for example when searching for Anchored Frames. This is represented in the xml file as
<findstring></findstring>
- At the next start of FM with the script things work as expected.
- As long as I do not save a new set of settings nothing strange happens and the next FM session is OK.
- Saving new settings of course recreates the xml file. And now the previously existing
<findstring></findstring>
are saved to the file as
<findstring/>
- This is absolutely correct in the sense of XM, but ...
- ... in the next FM session these empty elements create problems. There is no more a distinction between an empty string, a null or undefined element. See my test script (after dl rename *.txt to *.jsx).
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?

