![]() |
XmlDiff TUTORIAL |
XmlDiff TUTORIAL
xmldiff [Options] from_file to_file
xmldiff [Options] [-r] from_directory to_directory
Options:
-h, --help
display this help message and exit.
-V, --version
display version number and exit
-H, --html
input files are HTML instead of XML
-r, --recursive
when comparing directories, recursively compare any
subdirectories found.
-x, --xupdate
display output following the Xupdate xml specification
(see http://www.xmldb.org/xupdate/xupdate-wd.html#N19b1de).
-e encoding, --encoding=encoding
specify the encoding to use for output. Default is UTF-8
-n, --not-normalize-spaces
do not normalize spaces and new lines in text and comment nodes.
-c, --exclude-comments
do not process comment nodes
-g, --ext-ges
include all external general (text) entities.
-p, --ext-pes
include all external parameter entities, including the external DTD
subset.
--profile=file
display an execution profile (run slower with this option),
profile saved to file (binarie form).
if you process two files file1 and file2 which respectively contain:
<memory>
<mailbox path="/var/spool/mail/almaster"/>
<server-socket port="7776" recipe="pia.PDA"/>
<server-socket port="7777" recipe="proxy.Web proxy"/>
<email_addr mine="yes">almaster@logilab.org</email_addr>
<junkbuster-method value="18" />
<spoken-languages>
<language name="italian" code="it" />
<language name="english" code="fr" />
<language name="english" code="en" />
</spoken-languages>
</memory>
and
<memory>
<box path="/var/spool/mail/almaster"/>
<server-socket port="7776" recipe="pia.PDA"/>
<server-socket port="7797" recipe="proxy.Web proxy"/>
<email_addr mine="yes">syt@logilab.org</email_addr>
<junkbuster-method val="18">
<newson/>
</junkbuster-method>
<spoken-languages new="new attribute">
<language name="english" code="fr" />
<language code="it" name="italian" />
</spoken-languages>
<test>
<!-- this is an append test -->
hoye!
</test>
</memory>
executing xmldiff file1 file2 will give the following result:
rename_node, /memory[1]/mailbox[1], box]
[insert-after, /memory[1]/junkbuster-method[1],
<spoken-languages new="new attribute">
<language code="it" name="italian"/>
</spoken-languages>
]
[insert-after, /memory[1]/spoken-languages[1],
<test>
<!-- this is an append test -->
hoye!
</test>
]
[update, /memory[1]/email_addr[1]/text()[1], syt@logilab.org]
[rename_node, /memory[1]/junkbuster-method[1]@value, val]
[append-first, /memory[1]/junkbuster-method[1],
<newson/>
]
[move-first, /memory[1]/spoken-languages[2]/language[2], /memory[1]/spoken-languages[1]]
[update, /memory[1]/server-socket[2]@port, 7797]
[remove, /memory[1]/spoken-languages[2]]
This give you a list of primitives to apply on file1 to obtain file2
(you should obtain file2 after the execution of all this script!). See
[4] and [5] for more information.
The script above tell you the 9 actions to apply on file1:
Note all xpath are relative to the file1 with previous steps applied.
if you would have typed "xmldiff -x file1 file2", you would have
obtained the same thing described as an Xupdate output (see [3]).
<?xml version="1.0"?>
<xupdate:modifications version="1.0"
xmlns:xupdate="http://www.xmldb.org/xupdate">
<xupdate:rename name="/memory[1]/mailbox[1]" >
box
</xupdate:rename>
<xupdate:insert-after select="/memory[1]/junkbuster-method[1]" >
<xupdate:element name="spoken-languages">
<xupdate:attribute name="new">
new attribute
</xupdate:attribute>
<language code="it" name="italian"/>
</xupdate:element>
</xupdate:insert-after>
<xupdate:insert-after select="/memory[1]/spoken-languages[1]" >
<xupdate:element name="test">
<!-- this is an append test -->
hoye!
</xupdate:element>
</xupdate:insert-after>
<xupdate:update select="/memory[1]/email_addr[1]/text()[1]" >
syt@logilab.org
</xupdate:update>
<xupdate:rename name="/memory[1]/junkbuster-method[1]@value" >
val
</xupdate:rename>
<xupdate:append select="/memory[1]/junkbuster-method[1]" child="first()" >
<xupdate:element name="newson">
</xupdate:element>
</xupdate:append>
<xupdate:remove select="/memory[1]/spoken-languages[2]/language[2]" />
<xupdate:append select="/memory[1]/spoken-languages[1]" >
<xupdate:element name="language">
<xupdate:attribute name="code">
fr
</xupdate:attribute>
<xupdate:attribute name="name">
english
</xupdate:attribute>
</xupdate:element>
</xupdate:append>
<xupdate:update select="/memory[1]/server-socket[2]@port" >
7797
</xupdate:update>
<xupdate:remove select="/memory[1]/spoken-languages[2]" />
</xupdate:modifications>
xmldiff discussion should take place on the xml-logilab mailing list.
Please check http://lists.logilab.org/mailman/listinfo/xml-projects for
information on subscribing and the mailing list archives.
|