Validate XML against XSD in pure ABAP
abap, xml, xml-validation, xsd
Solution
Incase anybody comes by...
As far as I've been able to find while searching around the internet so far, there is no native way in ABAP to validate an XML document against a XSD schema. The best option you have is a DTD.
My code samples aren't complete so copy and pasting won't work, but basically what I've done was save the XSD schema on the application server and the XML file in the temporary directory. I call the java program and pass it the XML and XSD file as arguments.
Here is the java code
Java XSD Validator
From ABAP, you can call this command and pass the file you saved with `OPEN DATASET`. Here is a code sample:
ABAP Validator and OS Command
It works, but it's rather slow. I'm on a computer with rather modest hardware compared to a live server, but it takes about 350ms per check with a small XSD and small XML.
I'm not sure if running it as a service or RFC will improve performance, but if you want it's worth a shot.
Problem
Is there there any standard way to perform validation of XML document using XSD in ABAP? As far as I know, there is an approach that utilizes XI/PI capabilities, but these are not available in our system. I think we might also use a workaround: make standalone Java RFC or a web service in any other language, that will take XML and XSD from SAP, perform validation and return result back to SAP; but this may be more complex and less reliable solution. Have you met similar task and how did you solve it? Any suggestions, comments and even questions of clarification are highly appreciated!