Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

Update Raw XML with Formula - Find Replace

bkclaw113
9 - Comet

I am working on a proof of concept to update the configuration of tools using the Update RAW XML with Formula action type from within the action tool and running into problems with using the replace function to locate the existing XML and replace it with my desired XML.

 

I have created a batch macro with 2 control parameters (Find and Replace). Those control parameters feed into a single Action tool that is using the Update Raw XML with Formula action type, and attempting to update the inner XML for the Input Data tool.

bkclaw113_1-1674474257424.png

 

 

bkclaw113_3-1674474317782.png

 

This works when I Find/Replace a single value like the file name

bkclaw113_5-1674474757793.png

Or a single unquoted attribute like Field Length

bkclaw113_6-1674474961893.png

 

However when I try to find a longer string that that includes both the tag and an attribute within the tag, like in this example where I am changing both the record limit and the input file name (note the string was copied directly from the macro's XML opened in Notepad ++)

bkclaw113_7-1674475068950.png

Alteryx appears not to find the string and so the configuration for the input in the macro is not modified. This feels like an issue with the syntax that is being searched for but I have no idea how to determine what the correct syntax should be. Anyone run into this before or have suggestions on how to find and replace large

 

So with the underlying XML as seen in notepad ++ as:

<File RecordLimit="" SearchSubDirs="False" FileFormat="0" OutputFileName="FileName">D:\Alteryx\Projects\Config Manager\Sample.csv</File>

 

When I find/replace looking for RecordLimit="" it works

But when I look for File RecordLimit="" it does not work

 

To get even more specific it works with a single space before record limit ' RecordLimit=""'

But does not work with the "e" from "File" and the space e RecordLimit=""

 

So I am guessing that maybe there is another character that needs to go around the attribute names found inside of an XML tag (forgive me if I am not using correct nomenclature as I am not an XML person) any suggestions?

 

 

 

 

 

 

 

15 REPLIES 15
OllieClarke
15 - Aurora
15 - Aurora

Hi @bkclaw113 I think the issue here is whether the values in your find/replace have quotes in them. as these could (for want of a better word) break the Replace() function, by terminating the string early. You could try wrapping the control parameter in single quotes, assuming they will never appear in the string, if the string could have a combination of double and single quotes, then it might get a bit tricky...

OllieClarke
15 - Aurora
15 - Aurora

@bkclaw113 just continuing on that thought, I'd always recommend using the test view in the interface designer so you can see the interface values, or use debug mode to see what is actually going on with the problem values. 

OllieClarke_0-1674478351763.png

 

ChrisTX
16 - Nebula
16 - Nebula

You mentioned viewing the XML in Notepad++.  Did you know you can view the XML for each tool in Alteryx, by changing the user setting "Display XML in Properties Window"?

 

ChrisTX_0-1674479834822.png

 

Are you just trying to change the path to your CSV file?  In your second screenshot, in the section "XML Element to Update", you have the first line highlighted in blue.  If you instead highlight the line for "File - value = D:\A;teryx....", you should be able to easily update the path to the CSV.  In that "XML Element to Update" section, the macro will update whichever line you have highlighted in blue.

 

And like @OllieClarke mentioned, in the Interface Designer window, the Test View button (magic wand) and the Debug button are a huge help.

 

Chris

bkclaw113
9 - Comet

@ChrisTX, yes I did know about viewing teh XML from within Alteryx, I just prefer using notepad++ as it is easier to copy into and out of and keep notes as I am trying different approaches.

 

Also the selection of the entire Input, verses the File tag is intentional as I this is just a POC and I ultimately want/need to be able to change any of the tags, so my find/replace needs to act on the entire configuration tag, not just a single child element.

bkclaw113
9 - Comet

 @OllieClarke since the values that I am using in the Find and Replace control parameters are being passed by value as strings, I am not including any (single or double) quotes in the strings, however I did manual testing and did use single quotes to wrap the strings which only contained double quotes and I still experienced the same issue. Also over the course of testing I did pass values that included double quotes and it worked:

 

Find: RecordLimit=""

Replace: RecordLimit="1"

 

Works without issue, so I do not believe it is the quotes

bkclaw113
9 - Comet

I am using the interface view and debug mode, as I agree they are terrific tools under normal circumstances to understand odd behavior like this, however in this case, particularly with using the replace function it either finds the search string and performs the replace, or it does not find it and nothing changes. Please let me know if there is something else that I am missing, but I don't think the answer lies in debug mode.

bkclaw113
9 - Comet

Just to add some more to this investigation, I took the simple piece that was working:

Find: RecordLimit=""

Replace: RecordLimit="1"

 

Then I used the generate rows to add every possible character from ascii 1 to 256 in front of each string. The only character that resulted in the replace being executed (and returning only a single row of data) was char(32) which is <space>. I then repeated the process to see if any character prior to the space would work and char(109) (lower case m) worked, which from viewing the raw XML (in either Alteryx or notepadd++) does not appear anywhere. Having success finding that 'm RecordLimit=""' worked as the search string I tried the generate rows again and no character before the 'm' caused the Find value to be found, so I am again at a loss for what to try next.

bkclaw113
9 - Comet

@atcodedog05 We talked about this a few weeks ago, wanted to bring the detail to your attention to see if you had any ideas now that it is out of the theoretical and into an actual workflow.

OllieClarke
15 - Aurora
15 - Aurora

Hey @bkclaw113 I've been having a play with this. I found that it was the chevrons which were causing the problem. 

Finding 

File RecordLimit="" 

and replacing with

File RecordLimit="15"

works fine, but it doesn't work when you include the < before File.

 

Luckily if you change your action tool to 'Update Outer XML', then I think that solves the issue. This means that you're including the xml tags in your replace function (more so in the find part), and so they will be updated. 

OllieClarke_0-1674497135606.png

 

Labels