xml » replace(xml,xpath,content,var)
Description
This command search against specified xml via xpath, and replace content against all matching instances. The final
(modified) XML is then stored in a data variable specified as var. Note that this command replaces the matching
XML nodes, not the content of those match nodes.
If xpath refers to attribute of xml, it will replace name of all matching attributes with specified content.
A few things to consider when modifying (append, prepend or replace) XML. Since,
xpathmay resolve to a XML node (as in<node>...</node>) or an attribute (as in<node attribute="...">...),contentmay be text or a well-formed XML snippet.
Therefore,
- If
contentis simply text (as in text content) and specifiedxpathresolves to one or more XML nodes, then the text content of such nodes will be impacted (i.e. appended, prepended or replaced). - If
contentis a well-formed XML snippet and specifiedxpathresolves to one or more XML nodes, then the specifiedcontentwill be converted into XML to affect (i.e. append, prepend or replace) those matching nodes. - If the specified
xpathresolves to one or more XML attributes, thencontentwill be used as attribute values to append, prepend or replace (depending on the command used) existing attribute values.
Parameters
- xml - the XML document or file
- xpath - the XPATH to specify the target area of impact
- content - the content to replace, may be text content, attribute value or well formed XML snippet
- var - the variable name to store the beautified content.
Example
Script:

Output:

