3 ms·
We also faced this problem at work a while back, although, for XML. My first iteration was similar in spirit to jsonpatch: a sequence of ops against the docume
by zamalek 12y ago
We also faced this problem at work a while back, although, for XML.
My first iteration was similar in spirit to jsonpatch: a sequence of ops against the document. A XML patches grew things because mighty unwieldy and confusing. The maintainability of "diff operations" is incredibly low.
What I did in my second iteration was to have the patch document "look" like the document you are trying to create. Here's a document that will give you the general gist of how it worked (it's somewhat hard to describe in words): https://gist.github.com/jcdickinson/57e3a7e481a7e79f90b4 https://gist.github.com/jcdickinson/57e3a7e481a7e79f90b4
There are some operations (foreach, etc.) that I haven't included in the sample that are designed in an "operation" manner for scenarios where the structural approach won't work.
Either way it makes patches a lot more manageable and you may want to consider using it as inspiration. I included something rough in the gist to get the grey matter rolling.