[6 of 9] Using keys to control alignment
Using keys to control alignment
Keys are very useful because they enable you to control, in a very precise way, how elements in the two documents are aligned. When two elements are compared, any child elements with the same element name and key will be aligned, in preference to any other correspondence.
In the sample XML below, the XML has been edited to:
- add a new
<p>element and - delete a
<p>element
<p> element, which is reasonable.
However, it may be important to track this as a deletion and insertion in this case. You can control this using keys to identify
each <p> element:
- click NO KEYS to return to the original example with no keys.
- click ADD KEYS to add keys to the paragraphs. With these keys the paragraphs are always aligned correctly, and the two
<p>elements are exchanged and not modified.
Keys are a very powerful feature when you are processing XML containing structured text, for example legal documents, or data.
You can use any string value for a key, e.g. the value of an existing ID attribute, using the deltaxml:key attribute. Keys can be generated as you generate the XML document or added by processing the document before comparison.
You can delete the keys afterwards if you no longer need them. Note these examples use the full context delta.
DeltaXML Input and Output
| Document 1 | Document 2 |
|
DeltaXML: Idle
|
|
|
loading...
|
|