Partager via


Escape characters illegal in XML with hex character reference through an Azure Function V2

Just now published sample code Visual Studio 2017 project on GitHub at https://github.com/daviburg/CSharpUtilities/tree/master/Sources/Daviburg.Utilities/Daviburg.FixToXmlCharacters demonstrating a C# Azure Function V2 that escapes characters illegal in XML to an hex character reference, i.e.  value.
We have seen users migrating from non-Microsoft platform to Azure iPaaS having difficulties with XML messages which did not comply to W3C's specification with regards to allowed characters. As Azure is in large based on .NET, which XML implementation conforms to the W3C requirement not to permit illegal characters, loading these XML messages in Azure services will generally fail. For instance, the Azure Logic App XML validation action will reject them as not XML.
There are different possible approaches as to what to do with illegal characters to repair an XML document. Much of the available code snippets simply suppress (delete) the characters. This might be troublesome as the full original message content is not preserved. This more elegant approach ensure the entirety of the original message content is provided, even if some part has to be escaped. It should be fairly straight forward to further un-escape the special characters once the XML processing is complete, through for instance a regular expression search.

Comments

  • Anonymous
    June 20, 2019
    This blog has been moved off the MSDN platform. Find further content and update at https://www.linkedin.com/today/author/daviburgComments are locked as part of the blog migration, so please reach out to your customer support contact for assistance with Microsoft products and services.