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
Below you can find an example how the Data Type could look like.
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.
NOTE
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?
Example 1
When we send the message were the company code field is too long for example we would get the error as shown below:
Example 2
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.
Further options:
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)
Conclusion:
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.
Petr.
as there were so many blogs on XML validation that
it’s becoming difficult to check 🙂
Regards,
Michal Krawczyk
Nice blog. Just wanted to know,shabarish had mentioned certain invalid xmls that had flaws in the hierarchy and the structure.
However, your example deals with the invalid format of fields. How would it validate the entire xml structure?
Kindly let me know.
This blog was very helpful to me. I am attending my first project in version 7.3 and had not yet turned on the validation of XML because it does not have access to the server folder and also because they knew about the change and I didn’t.
I just did a test and it worked perfectly.
BLOG came in great time.
Thank you!!
Regards
Bruno.
then is was worth blogging about it:)
thanks for the godo news Bruno 🙂
Regards,
Michal Krawczyk
Hi,
Really helpful blog…………Thanks Michal.
HItesh kumar
Hi Michal,
It seems, this concept is only applicable for ICO and does not work with dual stack in 7.3.
We have to maintain the schema in the server folder for both validations by AE and IE.
Thanks
navneet
Hi Navneet,
did you try it in dual stack?
this is applicable to both ico and classical scenario.
in 7.3 we don’t have maintain the schema as we used to it in 7.11. this is the feature of 7.3.
I have worked on 7.31 version dual stack. it was working fine.
Regards,
Muniyappan.
Hi Marasamy,
yes, i tried it in dual stack PI 7.3.
I got the error for both AE and IE validation in sender agreement.
Error:
Schema Not Available in Cache, try to validation with file system schemas. Validation With File System schemas also Failed. Schema ****.xsd not found in D:\usr\sap\DGX\****
When I saved the schema in the folder then it worked.
Thanks
Hi Navneet,
thanks for your reply.
can you share your system version(SP level)?
let us see if others can help on this.
are you telling that this works fine for ICO without saving the schema in folder?
Regards,
Muniyappan.
Hi Marasamy,
I have not tried with ICO. i will check this today(this should work as per others feedback).
My Version: PI 7.3 with SP09
Thanks
Hi Navneet,
as per this thread xml validation in sap pi 7.3(dual stack)
user has placed the xsd in the folder still he is getting the error.
not sure why it is happening.
Regards,
Muniyappan.
Hi Michal,
Thank you so much about XML Validation in PI 7.3. Its very useful whenever I use in our project. Keep up the good work.
Advanced wishes for New year 2014 🙂
Regards,
Hari Suseelan
Hi Michal, nice review!, quick question, it’s possible to disable from the XML validation the part that check the exact order of the elements contained in the Node? thanks
Hi Michal, nice review here,
i have activated validation but it seems to to take notice of optional fields.
If a field is optional an dis not provided in the payload i get a validation error (Field Missing)
Is this correct?
Regards
Juan