1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
use Range;
use ;
use crateapply_diff;
use crateComparison;
use crateStatus;
use crateEdit;
/// A natural XML diff comparison of two documents.
/// 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:
///
/// ```xml
/// <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:
///
/// ```xml
/// <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:
///
/// ```xml
/// <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:
///
/// ```xml
/// <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!`:
///
/// ```xml
/// <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`:
///
/// ```xml
/// <section a="A" b="B"><diff:attributes><c diff:attr-insert="">C</c></diff:attributes><p>Txt</p></section>
/// ```
///
/// Delete attribute `b`:
///
/// ```xml
/// <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:
///
/// ```xml
/// <diff:pi-insert><?my pi?></diff:pi-insert>
/// ```
///
/// And processing instructions that are to be deleted are presented like this:
///
/// ```xml
/// <diff:pi-delete><?my pi?></diff:pi-delete>
/// ```
///
/// ## Comments
///
/// Comments that are to be inserted are presented like this:
///
/// ```xml
/// <diff:comment-insert><!-- my comment --></diff:comment-insert>
/// ```
///
/// and for deleted comments:
///
/// ```xml
/// <diff:comment-delete><!-- my comment --></diff:comment-delete>
/// ```
/// Given a diff document, apply it.
///
/// This returns the XML for the document that results from applying the diff.
///
/// This is a low-level API to support the CLI you don't normally need to use.
/// If you want to verify that a diff document is correct, use
/// [`NaturalXmlDiff::verify`] instead.