Azure Function to Apply XML Validation (Basic)

  • Sandro Pereira
  • Feb 12, 2024
  • 5 min read

After the release of our two previous Azure Functions that will help us minimize or completely remove the need for an Integration Account:

Today is the correct time to release another Azure Function that will replace another Integration Account functionality: an Azure Function to Apply XML Validation.

📝 One-Minute Brief

Validating XML messages early helps prevent downstream errors and unstable integrations. This post shows how to build a basic Azure Function to validate XML against an XSD schema, making it a lightweight, reusable component for integration scenarios. The approach improves reliability while keeping validation logic centralized and easy to maintain.

Where you can already apply XML Validations

Of course, you can apply this functionality out of the box in:

  • Logic App Standard (without the need for an Integration Account)
XML validation
<validate-content unspecified-content-type-action="ignore | prevent | detect" max-size="size in bytes" size-exceeded-action="ignore | prevent | detect" errors-variable-name="variable name">
    <content-type-map any-content-type-value="content type string" missing-content-type-value="content type string">
        <type from | when="content type string" to="content type string" />
    </content-type-map>
    <content type="content type string" validate-as="json | xml | soap" schema-id="schema id" schema-ref="#/local/reference/path" action="ignore | prevent | detect" allow-additional-properties="true | false" />
</validate-content>

However, Logic App Consumption requires an Integration Account to provide those same capabilities out of the box.

The main goal of this function

Once again, our main objective with this specific version of this function was clear: use it in Logic Apps Consumption without relying on an Integration Account. We will explore this scenario in more detail in a future blog post.

When I mention this “specific version”, I mean exactly that. In the coming days, we will release two additional versions of the function, each adding extra functionality. We will cover those versions separately in upcoming posts.

Apply XML Validation (Basic)

XML (Extensible Markup Language) validation is the process of checking an XML document against a defined set of rules. Its goal is to ensure that both the structure and the content follow a specific format or standard. As a result, validation plays a key role in keeping integrations stable and predictable.

  1. Well-formed XML: focuses on syntax correctness. In other words, the document must respect the XML specification rules. These rules include proper element nesting, correct opening and closing tags, and quoted attribute values. When a document follows these rules, an XML parser can reliably read and process it.
  2. Valid XML: goes one step further. Besides being well‑formed, the document must also comply with a defined schema or a Document Type Definition (DTD). This schema specifies which elements and attributes are allowed, their data types, and how they relate to each other. Therefore, validation ensures that the XML structure matches what the receiving system expects..

There are several schema languages used for XML validation, with the most common being:

  • DTD (Document Type Definition): An older schema language that defines the structure and allowed content within an XML document. – Not supported in the Azure Function.
  • XML Schema (also known as XSD): A more powerful and expressive schema language that allows for more detailed specifications of the content and structure, including data types and namespace support.

XML parsers and validation tools perform XML validation by checking documents against a DTD or an XSD. These tools programmatically verify that the XML complies with the defined rules and structure.

As a result, validation plays a critical role in data exchange, configuration management, and content authoring workflows. It ensures that receiving systems and applications can correctly interpret and process the XML data.

What does this Azure Function do?

This Azure Function allows you to perform basic XML validations against an XML Schema.

To trigger this function, you need to:

  • In the Body, the XML payload that you want to be validated.
  • You should specify the following mandatory headers:
    • Content-Type as text/xml (or application/xml).
    • SchemaFileName with the name of the XML Schema (XSD) file present in the storage account.

The response will be:

  • 200 OK – Validation successful. If it’s a valid message.
  • Or 400 Bad Request with a list of errors if there is something invalid.

Notice that by default, if you send a message to be validated against a schema that doesn’t have the same target namespace and root node, the response will be an OK. This function also validates the type of message, so if you send a message that doesn’t correspond to that schema, you will get a 400 Bad Request.

Where can I download it?

You can download the complete Azure Functions source code here:

Hope you find this helpful! So, if you liked the content or found it useful and want to help me write more, you can buy (or help me buy) my son a Star Wars Lego! 

Thanks to my team member Luís Rigueira for helping me realize and implement this idea.

Author: Sandro Pereira

Sandro Pereira lives in Portugal and works as a consultant at DevScope. In the past years, he has been working on implementing Integration scenarios both on-premises and cloud for various clients, each with different scenarios from a technical point of view, size, and criticality, using Microsoft Azure, Microsoft BizTalk Server and different technologies like AS2, EDI, RosettaNet, SAP, TIBCO etc. He is a regular blogger, international speaker, and technical reviewer of several BizTalk books all focused on Integration. He is also the author of the book “BizTalk Mapping Patterns & Best Practices”. He has been awarded MVP since 2011 for his contributions to the integration community.

Leave a Reply

Your email address will not be published. Required fields are marked *

The Ultimate Cloud
Management Platform for Azure

Supercharge your Azure Cost Saving

Learn More
Turbo360 Widget

Back to Top