How to change the attribute valuep of xml using invoke code activity

please some ne help me on changing the attribute value of a xml string using invoke code activity.

below is the sample xml:
<soapenv:Envelope xmlns:soapenv=“http://schemas.xmlsoap.org/soap/envelope/” xmlns:rep=“http://www.constellation.com/pqr/Message/abcd” xmlns:mes=“http://www.constellation.com/pqr/Common/MessageHeader”>
soapenv:Header/
soapenv:Body
<ns0:abcdefgh xmlns:SOAP-ENV = “http://schemas.xmlsoap.org/soap/envelope/” xmlns:ns0 = “http://www.constellation.com/BGE/Message/abcdefgh”>
<ns1:MessageHeader xmlns:ns1 = “http://www.constellation.com/abcded/Common/MessageHeader”>
ns1:Organizationxxx</ns1:Organization>
ns1:ObjectReferenceyy</ns1:ObjectReference>
ns1:ServiceTypeww</ns1:ServiceType>
ns1:TransactionIDxxxxxx</ns1:TransactionID>
ns1:Timestamp2eeeeeeee</ns1:Timestamp>
ns1:SenderIDeeeeee</ns1:SenderID>
ns1:SenderNameerewrere</ns1:SenderName>
ns1:HostName635635547874</ns1:HostName>
ns1:ObjectTypekjkljkl</ns1:ObjectType>
</ns1:MessageHeader>
ns0:TargetQueueNamejhjknlkjdasldjaslda</ns0:TargetQueueName>
ns0:FA0495470401</ns0:FA>
</ns0:abcdefgh>
</soapenv:Body>
</soapenv:Envelope>

I want to modify the value of “FA”. please someone help me on this.

Thanks in Advance.

You can do that in two different ways @Venkat_Gandham

  1. Deserialize the XML and get the value of FA using for loop by looping through the names of nodes and then use innertext to change the value

or

  1. You can use string manipulations to replace the value within the string which is an easy way but not the standard way

could u please post the sample code for string manipulations

Please check the workflow directly to replace the value, but this is not the efficient way to replace in XML.

ReplaceStringBetweenTwoString.xaml (5.1 KB)

@Venkat_Gandham
As @HareeshMR mentioned it might be good to have a look on alternates to regex

The Element FA you can retrieve via API e.g LINQ to XML and the a simple statement looks like:
xDoc.Root.Descendants(ns0 + “FA”).First()

And exactly on this part we have to pay attention on the important fact: XML is using Namespaces. This we do handle with an initialized XNamespace for xmlns:ns0="http://www.constellation.com/BGE/Message/abcdefgh and using it with ns0
The statement is fetching the first FA Descendent from Root Base (a like XPAth //FA[ X ]) X=Index

  • Setting the Value of FA Element can be done with the XElement.Method SetValue
  • Once we have changed the Value we do save the altered XML file, again with the XML Api.

There are alternates in place as well. But even this options (e.g. XPATH Statements) requires the correct referencing/usage of the relevant name space

Let us know your questions and feedback