Posts

Showing posts with the label Xpath

Extensible Xml Diff with SWI-Prolog

The previous article presented 2 alternatives for calculating the diff predicates, such as   diff(on(//'NEST', @type), from(//bird, @name)).   using a common strategy for matching objects, and a different strategy for matching sub-nodes of these objects, in the tree_d2_map and tree_d2_lcs implementations respectively.   This approach led however to some code duplication, and thus to the increase of the number of predicates which one might have to write to produce a diff.   The present article now introduces a generic diff implementation that works as a “swiss-army knife”, enabling on-the-spot combinations of node set matching strategies.   Resources for this article Prolog source code and XML examples are available on  [github] , and are linked to this article. To help enhance the readability of the predicates’ output, some Xml elements below are sometimes “ellipsed” with a “…” . A new code structure for decoupling th...

Meaningful Xml Diffs with SWI-Prolog

Introduction Building on the previous article I wrote on using the SWI Prolog Xpath predicate for analyzing Xml Node Set relationships, I now describe a way to produce a tree oriented diff based on similar techniques. The goal of such a diff is to identify objects of 2 Xml trees which differ by a given sub-node. In a sense is that diff not a fully general diff, as it focuses on 2 or 3 levels: object sub-or-descendant node resp. property when required, property of the sub-or-descendant node specified by the user, within the Xml tree structure. Another important goal of this diff is to be able to accommodate a different ordering of these objects in the Xml structure, which is normally a constraint which most editors or developer tools can’t cope with. In the following sections I will again use a similar fictitious tree example as in the precedent article. Resources for this article Prolog source code and XML examples are available on  [github] ...

Powerful Xml Analysis with Prolog

Image
Introduction SWI Prolog provides a Prolog-friendly version of Xpath which consists of defining Xpath expressions as Prolog  terms . The actual API is documented  here . There are a few hurdles which one has to face, coming from using standard Xpath expressions (e.g. with XSLT) and having to transpose them into the Prolog flavor. Having integrated this difference with the standard, one can quickly measure the immense flexibility offered by these Prolog xpath predicates for performing some complex Xml Analysis. Key to this is the possibility to use unification involving some Xml intermediate Node objects, using them as current (local) context nodes, which in Xpath is referred to as the “Axis”. Another concept of Xpath, the NodeSet, can also be covered elegantly by unification. I would like now to showcase this on a small example, using a fictitious tree description, and some imaginary information one would like to extract from it. Resources for ...