Search code examples
xmlxpathbiztalkbiztalk-2013

XPath to set multiple values


In the message below, I want to set the 2 'invunique' nodes to a parameter vParam. I can easily set 'cvalue' using

xpath(MyMsg.Body, "//*[local-name()='cvalue']") = vParam;

But I've not found a nice way of setting the 2 'invunique' nodes in 1 XPath statement, any ideas?

<ns0:newcase xmlns:ns0="http://MyNamespace/v1-0">
<ns0:caseheader>
  <ns0:caseunique>10</ns0:caseunique> 
</ns0:caseheader>
<ns0:financials>
 <ns0:invoices>
   <ns0:invoice>
       <ns0:caseunique>10</ns0:caseunique> 
       <ns0:invunique>10</ns0:invunique> 
       <ns0:invudfs>
         <ns0:invudf>
           <ns0:invunique>20</ns0:invunique> 
           <ns0:cvalue>cvalue_0</ns0:cvalue> 
           <ns0:otherdesc>otherdesc_0</ns0:otherdesc> 
         </ns0:invudf>
       </ns0:invudfs>
  </ns0:invoice>
 </ns0:invoices>
</ns0:financials>
</ns0:newcase>

Solution

  • As far as I know (I haven't tested this unfortunately), the xpath function 'setter' will only be able to update the first match. If you would have a second cvalue node, only the first one would have been updated.

    Any reason why you would want both updated in one statement instead of having 2 statements?

    If this is a recurring node, I would suggest to involve a mapping or helper class instead.