How to find and replace (manipulate) in XML


Badge +2

I have the following xml from repeat table of form. I need to replace user ID (for example PROCTORE lamfuki with this user's display name "Tommy Lamfukilami") in an XML with that user's display name. Any suggesion? 

<?xml version="1.0" encoding="utf-8"?><RepeaterData><Version /><Items><Item><Discipline type="System.String">Evaluation</Discipline><DisciplineApprover type="System.String">PROCTORE	lamfuki</DisciplineApprover><StatusOfWork type="System.String"></StatusOfWork><DateOfApproval type="System.DateTime"></DateOfApproval></Item><Item><Discipline type="System.String">Initial Design</Discipline><DisciplineApprover type="System.String">PROCTOREcschwab</DisciplineApprover><StatusOfWork type="System.String"></StatusOfWork><DateOfApproval type="System.DateTime"></DateOfApproval></Item><Item><Discipline type="System.String">Changed Design</Discipline><DisciplineApprover type="System.String">PROCTOREmsteel</DisciplineApprover><StatusOfWork type="System.String"></StatusOfWork><DateOfApproval type="System.DateTime"></DateOfApproval></Item><Item><Discipline type="System.String">Proposed Design</Discipline><DisciplineApprover type="System.String">PROCTORE	lamfuki</DisciplineApprover><StatusOfWork type="System.String"></StatusOfWork><DateOfApproval type="System.DateTime"></DateOfApproval></Item><Item><Discipline type="System.String">Production Design</Discipline><DisciplineApprover type="System.String">PROCTOREcschwab</DisciplineApprover><StatusOfWork type="System.String"></StatusOfWork><DateOfApproval type="System.DateTime"></DateOfApproval></Item><Item><Discipline type="System.String">Quality Group</Discipline><DisciplineApprover type="System.String">PROCTOREmsteel</DisciplineApprover><StatusOfWork type="System.String"></StatusOfWork><DateOfApproval type="System.DateTime"></DateOfApproval></Item><Item><Discipline type="System.String">Quality Management</Discipline><DisciplineApprover type="System.String">PROCTOREcschwab</DisciplineApprover><StatusOfWork type="System.String"></StatusOfWork><DateOfApproval type="System.DateTime"></DateOfApproval></Item><Item><Discipline type="System.String">Final Management</Discipline><DisciplineApprover type="System.String">PROCTOREmsteel</DisciplineApprover><StatusOfWork type="System.String"></StatusOfWork><DateOfApproval type="System.DateTime"></DateOfApproval></Item></Items></RepeaterData>

8 replies

Userlevel 5
Badge +13

There is a replace string action that will let you specify the string to search for, what string to search, what to replace it with, and what to output your new string to

Replace Substring in String 

Badge +2

Yes I know about that function. I need to replace all the user ID (and they are all different) and user's display name. Basically I need to manipulate the XML.  

Userlevel 5
Badge +13

Then you need to use regular expression to find the matching pattern, put that in a variable, then use that variable as your "string to search for," and you can make this variable a people variable so you can then use display name to replace it by formatting the variable when you put in the "string to replace with." You can do this in a loop to get them all.

Can you give some more details on your requirement? Like why these aren't already being shown as the display name on the form or why you need them formatted? There may be an easier/better way to accomplish what you want here.

Badge +2

I dont have problem getting display name. The problem is to loop through each item then each DisciplineApprover and replace. I want the same XML I posted but the end XML will be with Display Name.

I am doing this for List View. 

Userlevel 5
Badge +13

Check out this blog about how to get the "people" into a collection variable you can loop through: Nintex Forms/Workflow - Parsing Repeating Section Data - Vadim Tabakman 

Badge +2

Thanks Courtney but I hated that article because I spent days and never been able to get the UDA to work. It was very frustrating. However, I am open to a better article. It could be my Nintex workflow version. (2010,  2.4.9.0) 

Userlevel 5
Badge +13

Haha, I used that article to implement my requirement here: People picker in repeating section with multiple values used to generate email 

Essentially, here's the step by step:

  1. For my workflow, I did not name the repeating section and extract it from the form data. Instead, I connected by repeating section to a field called repeatingSectionData which is a multiple lines of text box that is plain text. Plain text is very important! This will put our XML of our repeating section into a list column.
  2. Inside the repeating section, on the form, I named the fields inside stuff like repeatingPeoplePicker, repeatingDate, etc
  3. In the workflow I put a set variable action that sets a text variable called textXML to {Current Item:repeatingSectionData}203594_pastedImage_2.png
  4. Then I executed Vadim's Regular Expression replacements on this variable like so (this is just one of the three): 203595_pastedImage_3.png
  5. Then I queried the XML to get my users into a collection variable (repeatingUser is what I named the user field in my form):  203597_pastedImage_5.png
  6. Now I have a collection variable of all of my users. I wanted to send an email per item, so here's where we diverge in our needs. So, I'll continue on with the steps you should be able to take to get your needed result.
  7. Insert a For Each into your workflow. The Input Dictionary or collection should be your collection of users. If you want, before this step, you can remove your duplicate users if you may have them:203598_pastedImage_6.png
  8. Inside your For Each you should now have a "replace string" action. You want to search for itemUser, and replace it with itemUser formatted into Display Name. The source string should be the XML variable from earlier and that should be the output as well.

Let me know how this fares for you!

Userlevel 5
Badge +14

what is the form control type that you use to capture those users (approvers) IDs?

is it People or group control?

Reply