diff

Function diff 

Source
pub fn diff(xml_a: &str, xml_b: &str) -> Result<String, Error>
Expand description

Given XML document A and XML document B produce a diff document.

This document describes how to get from A to B.

The diff document adds a new namespace prefix diff for the http://paligo.net/nxd namespace URI.

§Elements

New elements that are inserted are marked by the diff:insert attribute with an empty value:

<section><p diff:insert="">This is a new paragraph.</p></section>

Elements that are deleted are marked by the diff:delete attribute with an empty value:

<section><p diff:delete="">This is a paragraph that is deleted.</p></section>

If the document (top) element is replaced, we can’t just do a bare diff:delete and diff:insert of the elements, because well-formed XML documents can only have a single document element. Instead, a special placeholder diff:root element is inserted to wrap the insert and delete:

<diff:root xmlns:diff="http://paligo.net/nxd"><doc diff:delete="">A</doc><doc diff:insert="">B</doc></diff:root>

§Text

Text updates are marked with diff:text-insert and diff:text-delete elements:

<section><p>This is a paragraph with <diff:text-insert>new text</diff:text-insert> and <diff:text-delete>deleted text</diff:text-delete>.</p></section>

§Attributes

Attributes changes are represented by a new diff:attributes elements inserted as the first child of the element in which the attributes changed. Each attribute update is represented by a child element that is marked with the diff:attr-update, diff:attr-insert or diff:attr-delete attributes (with empty values):

Update attribute a to the new value A!:

<section a="A" b="B"><diff:attributes><a diff:attr-update>A!</a></diff:attributes><p>Txt</p></section>

Insert a new attribute c with value C:

<section a="A" b="B"><diff:attributes><c diff:attr-insert="">C</c></diff:attributes><p>Txt</p></section>

Delete attribute b:

<section a="A" b="B"><diff:attributes><b diff:attr-delete=""/></diff:attributes><p>Txt</p></section>

§Processing instructions

Processing instructions that are to be inserted are presented like this:

<diff:pi-insert><?my pi?></diff:pi-insert>

And processing instructions that are to be deleted are presented like this:

<diff:pi-delete><?my pi?></diff:pi-delete>

§Comments

Comments that are to be inserted are presented like this:

<diff:comment-insert><!-- my comment --></diff:comment-insert>

and for deleted comments:

<diff:comment-delete><!-- my comment --></diff:comment-delete>