Modify attributes with UiPath

I have what I feel is a fairly straight forward question and I am a bit frustradted that I can not figure it out myself.

I have an XML file.

Looks like this (in i.e. c:\temp\file.xml):
< ?xml version=“1.0” encoding=“ISO-8859-1”?>
< Main>
< Product>
< ProductID itemNumber=“99999”>
< SubProduct numberOfInstances=“1” unitType=“Each”>
< ProductID itemNumber=“10000”>
< Amount value=“123” UOM=“mg”/>
< /ProductID>
< /SubProduct>
< /Product>
< /MainDeclaration>

The itemNumber will occurr a many times and I want to replace the original value with a running number (1, 2, 3 …).

I basically want to do a find / replace, but with a counter. Maybe UiPath is overkill, but there can be other use cases later so figured it would be nice to have :slight_smile:

Basically I can read the xml, find the attribute, bu I can not replace it in the original file.

Please help me :slight_smile:
TestXML.xaml (8.4 KB)

Attached the XAML as samle

use my sequence
test11.xaml (9.0 KB)

  • first i read the xml file to string variable txt
  • then assign ProductID itemNumber="([\d]+)">\s to a regex match variable
1. textToReplace = regexMatch.Groups(0).Value  //<ProductID itemNumber="10000">
2. currentProductNumber regexMatch.Groups(1).Value  //10000

  1. newProductNumber = currentProductNumber+1

  2. txt = txt.Replace(textToReplace, textToReplace.Replace(currentProductNumber, newProductNumber))

  3. write txt back to file

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.