Some hints when using the xml patch form
How to:
Copy some operation or type manually, e.g. <add
sel="*"><bar/></add> and press the patch button. The
tool on the server side keeps track of the target document (to be
patched) and encapsulates given patch operations with appropriate xml
prolog etc. So you need to type those single patch operations
only. And certainly you can add several operations onto the form.
Some shortcuts:
In order to avoid typing, you can
write: <a> instead of <add>, <d> instead of
<remove> and <r> instead of <replace>
Submit your own document as a baseline document:
<replace sel="*">[your root element containing all the children, ns declarations etc.]</replace>
This can contain e.g. a default namespace declaration:
<replace sel="*"><root xmlns="urn:foo">
<bar a="1"/>
</root></replace>
Handling of namespaces (within selector values and within changed/added "payload"):
First submit a namespace file as a baseline document.
Then you can apply patches like (textarea in the form):
xmlns="urn:foo"
<add sel="root"><bar/></add>
so <bar> is qualified with "urn:foo" namespace URI as well as the sel selector value is.
Similarly (the same end result) can be achieved by:
xmlns:x="urn:foo"
<add sel="x:root"><x:bar/></add>
Add a set of sibling nodes (text, element, comment or PI nodes):
<add sel="*/foo[@a='1']" pos="before"><foo a="3">
<bar/>
<t:test xmlns:t="urn:test">
<t:bar xml:id="r123"/>
</t:test>
</foo>
<!-- comment -->
<?foo p="e"?>
</add>
Add a qualified element + whitespace text node
xmlns:x="urn:foo"
<add sel="*/x:foo[@a='1']"><x:foo a="3"/>
</add>
or similar result with:
xmlns="urn:foo"
<add sel="*/foo[@a='1']"><foo a="3"/>
</add>
Add an attribute:
<add sel="*/foo[@a='1']" type="@b">foo</add>
Add a qualified attribute:
xmlns:y="urn:foo"
<add sel="*/foo[@a='1']" type="@y:b">bar</add>
Add a namespace declaration:
<add sel="*" type="namespace::p">urn:xxx</add>
Replace an element:
<replace sel="*/foo[@a='3']"><bar a="3"/></replace>
Replace an attribute value:
<replace sel="*/foo[@a='1']/@a">2</replace>
Replace a comment node:
<replace sel="*/comment()"><!-- new comment --></replace>
Replace text node content:
<replace sel="*/foo/text()[1]">replaced text</replace>
Replace a PI node:
<replace sel="*/processing-instruction('foo')"><?bar="rrr" s="gggggg" ?></replace>
Remove an element:
<remove sel="*/bar[@a='3']"/>
Remove an element with id() function:
<remove sel='id("r123")'/>
Remove an attribute:
<remove sel="*/foo[@a='2']/@a"/>
Remove a comment node and the immediate following whitespace node:
<remove sel="*/comment()" ws="after"/>
Remove a text node:
<remove sel="*/text()[1]"/>