Skip to Content
Technical Articles
Author's profile photo Appala Naidu Uppada

Cloud Integration- Working with XML Validator

Introduction:

SAP Cloud Integration offers capabilities to validate the XML payload against a given XML Schema. XML Validator (version 1.x) can validate XML against the XSD schema 1.0.

With September 2018 release, this validation capability has been enhanced to provide the support for XSD  schema 1.1 as well. This release is planned to reach customers after September 30.

In this blog, I would describe distinctive features of XMLValidator that helps you to validate XML payloads.

Scenario 1: Validate XML against XML Schema– Stop Message Processing on Validation Failure  

Consider a scenario where you want to stop processing the message as soon as the validation error occurs. For demonstrating the scenario, I created a simple integration flow as shown below:

Configuration: 

  XMLValidator: Browse the XSD and keep the Prevent Exception on Failure checkbox unchecked.

 

Exception Content Modifier: Enter the header in the Message Body of the Content Modifier as shown below.

 

Run the scenario with a Validation error: 

You would see the exception from the Exception sub process as shown below:

Tracing of the message flow looks as shown below:

Scenario 2: Validate XML against XML Schema – Continue Message Processing During Validation Failure

Consider a scenario where you want to continue processing the message even after the validation error occurs on XML Validator.

For demonstrating the scenario, I extended the above integration flow as shown below.

Configuration:

XML Validator : Select Prevent Exception on Failure checkbox

Router:

Create a router with a condition ${header.SAP_XmlValidationResult} != ‘null’ to handle the scenarios in case of validation failures .

Once Prevent Exception on Failure option is checked,  the processing will continue processing without throwing an exception. You can handle the validation error scenarios with a route condition as shown below:

After Validation Error Content Modifier: In the Validation_Error route content modifier add Validation Error Result: ${header.SAP_XmlValidationResult} in the Message Body to capture the validation result.

 

Run the scenario with a Validation error: 

You would get the output from Validation_Error route as shown below:

 

Tracing of the Message flow looks as shown below:

NOTE: All the headers are case-sensitive. Use SAP_XmlValidationResult with the same case-sensitivity.

NOTE: The Validation Result is also available as an attachment in the Message Processing Log.

 

Scenario 3: Validate XML against XML Schema 1.1

XML schema 1.1 comes with a lot of features like Assertions. SAP Cloud Integration started supporting XSD 1.1 with XMLValidator (version >= 2.x). For more details on XML Schema 1.1 features, you may refer the documentation .

In the above example scenario, consider that I would like to introduce another conditional validation on minprice and maxprice. The condition that I want to apply is minprice should be less than maxprice.

 In the xsd, I just need to introduce a condition <xsd:assert test=”minprice le maxprice” /> 

 On running the scenario, you would get the additional assertion validation errors as shown below:

You may also refer the documentation from Saxon to understand the line-number and column-number

NOTE: From XMLValidator version 2.0 onwards, only SAP_XmlValidationResult header is retained. All the old headers like XmlValidationResult are deprecated.

 

Conclusion:  

      We learnt about different capabilities of XMLValidator with examples from different scenarios. See you again with another blog on exciting new features from Cloud Integration!

 

 

 

 

 

Assigned Tags

      4 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Kevin González
      Kevin González

      Very useful blog!

      I have one question. Is it possible to detect errors about strange characters?
      For example
      "[a-zA-Z0-9_. ' ! @ # $% ^ * () _ + = {} | /:;,>? / `~]". As I know, in the standard XML only is possible use xs: pattern value properties to detect like fix structure of data. but it is possible to make any dynamic,I mean you have a string like abcd * e. I would like to detect * and say "error,is not a valid format"

      Regards:)

      Author's profile photo Kevin Laevers
      Kevin Laevers

      Thanks for the blog! In your router, ${header.SAP_XmlValidationResult} should be ${property.SAP_XmlValidationResult} != 'null', as it's a property and not a header.

       

      Author's profile photo Alfaran Aftab
      Alfaran Aftab

      Hi,

      I tried out your solution and it works great. Only issue is the router condition should be ${header.SAP_XmlValidationResult} != null

      instead of

      ${header.SAP_XmlValidationResult} != ‘null’

      because in your case it seems to be matching the SAP_XmlValidationResult to a string that is 'null' and not actually null. In your solution it goes to the failed route for both a success and failure scenario.. you can reproduce the same in simulation mode.

      Thanks!

      Author's profile photo CPI Corona
      CPI Corona

      hola, hice la parte de excepcion, pero cuando lo ejecuto me aparece este error, pongo imagenes del iflow y como se utilizo.