Validate XML against XSD in pure ABAP
Asked Answered
H

2

16

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!

Hodgson answered 10/7, 2014 at 11:4 Comment(2)
As far as I know there is no function module/method of a class delivered in SAP standard. I also searched for it some time ago and was not able to find anything. I guess you are stuck with the idea of calling an external service to do that.Burkhart
A possible "solution" using java on the application-server to utilize xerces and/or convert the XSD to DTD: scn.sap.com/thread/3535431Strobila
N
0

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.

enter image description here

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.

Nernst answered 30/1, 2016 at 22:58 Comment(0)
D
0

Use this this report for XSD-related validation in ABAP: RPCXMLK0_VALIDATE
It can be launched programmatically as well.

Drops answered 28/12, 2015 at 15:26 Comment(2)
This uses the SAP-GUI to execute the essential Validation on a Windows-Client as far as I could get it from the source. Would be no solution for a backgroundjob if not on a Windows Server.Hackathorn
The OP had no explicit requirement of running validation only in background or without GUI, so this is also a valid option.Drops
N
0

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.

enter image description here

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.

Nernst answered 30/1, 2016 at 22:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.