Skip to Content

Schema Validation of Incoming Message

One of the challenges in SAP XI is validation of incoming messages. Per default this is not supported by SAP XI. Only validation of outgoing messages is supported.

In this weblog I will show a simple way to validate incoming messages using its XML Schema.

It is assumed that you have a functioning Interface Mapping and that you are using a XML Schema describing the incoming message.


1. Open your Interface Mapping.

2. Add a new line to the list of Message Programs.

3. Move the line to the beginning of the list.
4. Set type to ‘Message Mapping’
5. Create the new mapping.

6. Supply name and namespace for the Message Mapping.

7. Select External definition in both source and target message.
8. Select top-level element in both source and target message.
9. Click ‘Map Selected Fields and Substructures If Names Are Identical’

10. Save and close the Message Mapping.
11. Save and test the Interface Mapping. Try removing a required element from the source message. This should result in an error message

You must be Logged on to comment or reply to a post.
  • I’ve tried you technique for schema validation. It works fine when checking for the absence of data elements.  However, it does not work when for validating minlen, maxlen, and other element attributes.   Does this technique work for this type of schema validation?
    • Hello James.

      Thank you for your feedback.

      I did a bit of testing and I ran into the same type of restriction as you did.

      I tested by creating a Message Type and by importing an external XSD definition. In both cases the validation does not catch the restriction of minLength and maxLength.

      Furthermore I created a small standalone application to test the SAP XML Toolkit. When running this application the toolkit correctly returns an error if one of the restrictions are not met.

      My understanding of things was, that SAP XML Toolkit was used behind the scenes when running SAP XI scenarios. Either SAP uses a different XML parser in XI or they set up the toolkit in a special way where it ignores these restrictions.

      A work-around to test for minLength/maxLength could be to create a user-defined function (UDF) that takes the three inputs (testingValue, minLength, maxLength). If the ‘testingValue’ is not within the specified lengths, the UDF should throw a runtime exception to stop execution.

      I hope SAP soon comes with some sort of ‘business rule engine’-solution, so that we are able to do more advanced validation of incoming messages.

      Best regards,

      • The technique described does not provide actual schema validation. The “restrictions” you have experienced are a symptom of this.

        The SAP XML Toolkit can perform schema validation when parsing XML, but this must be explicitly requested when invoking the parser. XI’s Message Mappings do not do this. If they did, there would be no need to add a separate mapping step for validation, because all Message Mappings would automatically perform schema validation by themselves.

        The validation provided by the technique described is quite rudimentary and based on a single attribute of Message Mappings: A Message Mapping will throw an exception if it is unable to produce a required target element or attribute, i.e. any element or attribute with a cardinality of 1…1 or 1…unbounded. In other words, what is being validated in this technique is that the source document contains at least one of every element and attribute required by its schema – nothing else.

        As you have discovered, the defined length of an element is not considered. Nor is the type of data contained. Indeed, you can add any number of extra elements and attributes that are outside the schema to the source document and this validation technique will not complain. All of these situations are caught in “real” schema validation.

        My distinguished colleague Morten Wittrock has described one approach that provides real schema validation in his blog (Validating messages in XI using XML Schema). Additionally, I will be presenting an SDN Member Session at SAP TechEd ’06 in Amsterdam on the topic of message validation (Validation of Messages in SAP NetWeaver Exchange Infrastructure – SDN Member Session EPI213 at SAP TechEd ’06 Amsterdam).