On 14/11/2008, at 8:33 AM, Noah Slater wrote:
On Fri, Nov 14, 2008 at 08:19:22AM +1030, Antony Blakey wrote:
The relevent section from XQuery Update,
http://www.w3.org/TR/xquery-update-10/#id-update-primitives, might
be useful
starting point for defining a JSON-encoded (recursive) EDL-based
structural
diff.
I think an XQuery/XPath type solution would be very interesting.
IMO the simplest thing that would work (ignoring representation) looks
something like this:
insert <json> in <jsonpath>
insert <json> after <jsonpath>
insert <json> before <jsonpath>
delete <jsonpath>
replace <jsonpath> with <json>
where jsonpath is roughly as: http://goessner.net/articles/JsonPath/
without the executable expressions.
Diff computation would undoubtedly generate a restricted subset of
jsonpath selectors, but it's worth supporting the wildcard/recursive
descent operations for clients.
Representing the update document as json itself would be clean, so an
EDL could look like this:
[
{ "replace":"$.post.comments[2].email"
"with":"[EMAIL PROTECTED]" },
{ "insert": { "email":.... } "in": "$.post.comments" }
{ "insert": { "email":.... } "after": "$.post.comments[5]" }
]
or, using a meta-encoding (which IMO is unneccessary)
[
{ "op":"replace" "path":"$.post.comments[2].email" "content":"[EMAIL PROTECTED]
" },
{ "op":"insert-in" "path":"$.post.comments" "content":
{ "email":.... } }
{ "op":"insert-after" "path":"$.post.comments[5]" "content":
{ "email":.... } }
]
I propose that these aren't declarative, but procedural, in the sense
that they are applied linearly and hence each path context is the
result of the proceeding edits, rather than the original tree. This
complicates the encoding of diffs but results in a much simpler apply
mechanism. But maybe it would be worth using a declarative form with a
constant context - I'm unsure about the tradeoffs.
Antony Blakey
-------------
CTO, Linkuistics Pty Ltd
Ph: 0438 840 787
He who would make his own liberty secure, must guard even his enemy
from repression.
-- Thomas Paine