Every xml patch file needs to have the header line and the diff root tag:
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<diff xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
...
</diff>
- add - add a block of xml text
replace - replace a block of xml text
remove - remove a block of xml text
There is a multi-node selection parameter (msel) which is not in the IETF spec, but is supported by the xmlpatch library. I do not know if X supports it, however, so I'd recommend making multiple unique entries instead of a multiple selection.
Some basic examples
All of these will use this basic source file:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<root>
<bar>
<foo a="1"/>
<foo a="2"/>
</bar>
</root>
Patch
Code: Select all
<add sel="root/bar">
<foo a="3"/>
</add>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<root>
<bar>
<foo a="1"/>
<foo a="2"/>
<foo a="3"/>
</bar>
</root>
Replace:
Patch
Code: Select all
<replace sel="root/bar/foo[@a='1']">
<foo a="3"/>
</replace>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<root>
<bar>
<foo a="3"/>
<foo a="2"/>
</bar>
</root>
Patch
Code: Select all
<remove sel="root/bar/foo[@a='1']"/>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<root>
<bar>
<foo a="2"/>
</bar>
</root>
The add command has three attributes that can be used:
- sel
type
pos
- sel
- sel
ws
Add an attribute
Patch
Code: Select all
<add sel="root/bar" type="@cat">3</add>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<root>
<bar cat="3">
<foo a="1"/>
<foo a="2"/>
</bar>
</root>
Patch
Code: Select all
<add sel="root/bar" pos="before">
<foo a="3"/>
</add>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<root>
<foo a="3"/>
<bar>
<foo a="1"/>
<foo a="2"/>
</bar>
</root>
Patch
Code: Select all
<add sel="root/bar" pos="prepend">
<foo a="3"/>
</add>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<root>
<bar>
<foo a="3"/>
<foo a="1"/>
<foo a="2"/>
</bar>
</root>
Patch
Code: Select all
<add sel="root/bar">
<foo a="3"/>
</add>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<root>
<bar>
<foo a="1"/>
<foo a="2"/>
<foo a="3"/>
</bar>
</root>
Patch
Code: Select all
<add sel="*/bar">
<foo a="3"/>
</add>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<root>
<bar>
<foo a="1"/>
<foo a="2"/>
<foo a="3"/>
</bar>
</root>
Patch
Code: Select all
<add sel="*/foo[@a='1']">
<cat a="3"/>
</add>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<root>
<bar>
<foo a="1">
<cat a="3"/>
</foo>
<foo a="2"/>
</bar>
</root>
Patch
Code: Select all
<replace sel="*/foo[@a='1']">
<cat a="3"/>
</replace>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<root>
<bar>
<cat a="3"/>
<foo a="2"/>
</bar>
</root>
Patch
Code: Select all
<replace sel="root/bar/foo[@a='1']/@a">3</replace>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<root>
<bar>
<foo a="3"/>
<foo a="2"/>
</bar>
</root>
Patch
Code: Select all
<remove sel="root/bar/foo[@a='1']/@a"/>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<root>
<bar>
<foo/>
<foo a="2"/>
</bar>
</root>
Source
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<root>
<bar>
<foo a="1">Some text here</foo>
<foo a="2"/>
</bar>
</root>
Code: Select all
<remove sel="root/bar/foo[@a='1']" ws="after"/>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<root>
<bar>
<foo a="2"/>
</bar>
</root>
{ 10.12.2013 - added xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" in diff-node to avoid Errors in Debuglog - UniTrader