FRENDS⁴ Common Components : Frends.Common.Data.QueryData.XpathReplaceValues

This task takes an XML document as an input and then executes the given XPath queries to find nodes and replace the value of those nodes. The task will return the altered XML document.

If single XPath evaluates to multiple nodes then all values will be replaced.

Input Parameters

  • Input
    • The document that the query and replacement is executed against. Input can be given in the following formats:
      • XML as a C# String
  • XPath
    • The XPath query that is to be executed for this object.
    • The XPath query must be written in a correct format. For more information about XPath see W3Schools XPath.
  • Value
    • Value used for replacement
      • string
  • ThrowErrorOnMissingNode
    • Boolean to determine whether to throw exception when Xpath does not find any nodes.

Output Result

  • String
    • A string containing the altered XML document.

Example Usage

For example calling this task, with the following inputs:

Value: Blorgh!

XPath:

XPath
/*[local-name()='root' and namespace-uri()='http://test0']//*[local-name()='handle' and namespace-uri()='http://test/v1']/*[local-name()='info' and namespace-uri()=''][local-name()='info' and namespace-uri()=''][contentType/text()='locationId']/*[local-name()='value' and namespace-uri()='']

and a C# XML String:

Input
<v0:root xmlns:v0="http://test0" xmlns:v1="http://test/v1">
    <v1:handle>
        <info>
            <contentType>Bears</contentType>
            <value>456</value>
        </info>
        <info>
            <contentType>locationId</contentType>
            <value>123</value>
        </info>
    </v1:handle>
</v0:root>

Will produce the following result:

Output
<v0:root xmlns:v0="http://test0" xmlns:v1="http://test/v1">
    <v1:handle>
        <info>
            <contentType>Bears</contentType>
            <value>456</value>
        </info>
        <info>
            <contentType>locationId</contentType>
            <value>Blorg</value>
        </info>
    </v1:handle>
</v0:root>

Errors

The task will return an exception The input data was not recognized. Supported formats are XML string and XMLDocument. if the input data could not be read correctly.

The task will return an exception "'Could not find any nodes with XPath: ' + Xpath" if the XPath did not match any elements and ThrowErrorOnMissingNode is true.