7

When defining an Azure API Management policy in a Bicep or ARM template, the format of the policy value may be set to rawxml (and rawxml-link) or xml (and xml-link). I know what the link formats are, however there is an unclear difference between rawxml and xml.

I have looked through the MS Docs on this (ApiManagement Policy Template Definition) but have not found any indicator as to the differences or purposes of either format. Googling around has not produced a straight answer anyway, at least to my google skills.

What is the difference between rawxml and xml?

Ijwu
  • 342
  • 1
  • 2
  • 8

1 Answers1

13

Policy in xml format must be a valid XML, i.e. all characters that are not valid in XML must be properly escaped. For example, that is how simple expression must look

<set-variable name="var" value="@(&quot;user id:&quot; + context.User?.Id)"/>

Policy in rawxml format utilizes razor syntax and it is what you see in Azure Portal when you edit policy code. In this format you don't need to escape XML invalid characters in expressions, like so:

<set-variable name="var" value="@("user id:" + context.User?.Id)"/>

Otherwise there is no difference, you can choose whatever format fits your needs best.

Vitaliy Kurokhtin
  • 7,205
  • 1
  • 19
  • 18
  • Is this documented somewhere? There are various magic strings like this in ARM/bicep that have limited documentation. – Matt Mar 21 '22 at 04:30
  • 3
    Only very briefly: https://learn.microsoft.com/en-us/rest/api/apimanagement/current-ga/api-policy/get#policycontentformat – Vitaliy Kurokhtin Mar 21 '22 at 16:12
  • Thanks, would be good if they also put this on the bicep doc! – Matt Mar 21 '22 at 18:10
  • 1
    You made my day! This was the last issue we were having. The error so other people can easily find this solution: `Name cannot begin with the '\"' character, hexadecimal value 0x22. Line 16, position 37."` – Jordy May 20 '22 at 06:29
  • TIL I learned that adding APIM policies to arm templates does not have to be a nightmare. @VitaliyKurokhtin you have changed my life lol. For years (literally) I've been struggling to properly escape apim policies thinking to myself "there has to be a better way, this is ridiculous". How I missed the docs on `rawxml`, beats me, but now I know! – Andrew Moreno Aug 17 '22 at 22:58