When I saw the article from my colleague (and co-author of our book from Genie Press) – Shabarish – XML / XSD Validation – An Alternative for SAP PIabout the XML validation in PI I decided that we need to sort some things out as it may start to get more and more confusing with XML validation in PI in general. As Shabarish mentioned as of PI 7.1 we have an option to use XML validation within PI but the configuration he described was only for 7.1 and 7.11 as it got changed a lot in the latest available release 7.3.
What are the changes then?
The most important one is that we no longer need to create any special XSDs nor we need to put them into any special folders of PI server. As of PI 7.3 we can use the Data Type object from Enterprise Service Repository for XML validation.
How to configure that?
Let me show you a simple XML validation data type example. The data type below needs to validate 3 fields:
a) Company code – this field needs to have always 4 chars
b) Currency – this field needs to contain 3 chars but always capital letters
c) Amount – the amount can be any integer but not more then 6 digts
In the second step you need to make sure the validation is switched on in the Integration Directory – the example below shows Integrated Configuration Object (ICO) but you can use a sender agreeement too of course.
|Once you activate the ID object the cache with your data type used for validation will be updated. If you do any changes in the Data Type as of this point (regarding XML validation) you always need to reactivate the ID part as well (so ICO object in this case).|
How does it work?
When we send the message were the company code field is too long for example we would get the error as shown below:
When we send a message where the currency field is “EURO” instead of “EUR” we would get the following error:
Can I see which schema is being used ?
You can always check the XML validation schema in:
– – Cache monitoring
– – – mapping runtime
– – – – XML schema
as shown in the figure below.
If you’d like to see what kind of validations you can put into the Data Type I’d suggest reading the related material from SAP first as there realy are a lot of options, starting from general facets with max, min length and finishing on much more sophisticated regular expressions – XSD Editor (Freely-Modeled Data Types)
XML validations in PI may not be perfect yet and sometimes you may still need to use other techniques like the one shown in an article from Shabarish but you need admin that it has become much easier to use than it was in the previous PI releases.