vendredi 8 mars 2019

Wisely save and read changed configuration (stored in XML file)

I'm dealing with a system which stores its configuration (in a broad sense) in XML files. It also enables overriding certain parameters by user. Right now if the configuration is changed by user whole XML file gets re-written (in user directory) with changes. It's however very inconvenient.

Let's imagine we have base configuration like:

<configuration>
    <groupOfProperties>
        <someProperty>Sample value</someProperty>
        <otherProperty>Sample other value</otherProperty>
    </groupOfProperties>
</configuration>

It got overridden by user and now changed one looks like this:

<configuration>
    <groupOfProperties>
        <someProperty>Changed value</someProperty>
        <otherProperty>Sample other value</otherProperty>
    </groupOfProperties>
</configuration>

It's cool and problem-less, unless our base configuration changed for some reason. For example - a new parameter was added:

<configuration>
    <groupOfProperties>
        <someProperty>Sample value</someProperty>
        <otherProperty>Sample other value</otherProperty>
        <newProperty>Sample new value<newProperty>
    </groupOfProperties>
</configuration>

Now user is not aware of that change and some black box reading XML file won't get new attributes which got changed in base. We can safely assume however that fact of not reading some of them is fail-safe and it affect only functional layer of system.

Is there any way to smartly save changed XML (preferably - just changed part) and easily 'merge' it with base file while processing request to get certain value?

I would imagine that what I actually save is not an XML file, but rather some kind of patch (https://tools.ietf.org/html/rfc5261). Then while reading certain attribute I would basically read base file and apply patch over it to get 'real' configuration?

I'm not looking for a very precise implementation, but rather a general solution to this problem and some conceptions how to solve it.

Many thanks for the answers!

P.S. In real system XML files are MUCH more complex than given examples.

P.S.2 Unluckily XML files (or any other flat files) are the only way to go for the system. We can call a tech-debt.

Aucun commentaire:

Enregistrer un commentaire