I have an XML document in an ILERPG variable. How can I validate this document against an XSD located in the IFS. Is there an SQL function that can do this?
Announcement
Collapse
No announcement yet.
XSD validation
Collapse
X
-
Thanks. After a bit of trial and error I have now been able to validate my xml document against the schema.
However, I have only been able to invoke the XMLVALIDATE function by using it in conjunction with an insert statement and then test the sql diagnostics after executing the statement. Is there any way to use the XMLVALIDATE function without having to insert the document into a table?
Comment
-
I'm not aware of a way to run an sql scalar function in SQLRPGLE without assigning the result somewhere. But it doesn't have to be assigned to a table, it can be assigned to an RPGLE variable using an SQL Set statement. e.g.
Code:exec sql set :rpgLowerStringVar = lower(:rpgUpperStringVar);
Code:exec sql set :validatedXmlDoc = xmlValidate(DOCUMENT :xmlDoc ACCORDING TO XMLSCHEMA ID foo.bar);
Code:dcl-s xmlStatus int(5) inz(0); exec sql set :xmlStatus = case when xmlValidate(DOCUMENT :xml ACCORDING TO XMLSCHEMA ID foo.bar) is null then -1 else 1 end;
Comment
-
P.S. this works for any of the many SQL scalar functions: https://www.ibm.com/docs/en/ssw_ibm_...rbafzscale.htm
There are plenty of functions that do not have an equivalent RPGLE BIF, like using VARCHAR_FORMAT() and TIMESTAMP_FORMAT() for date/time <==> String conversions. It's a useful tool for your RPGLE toolbox
-
-
Thank you for your brilliant suggestions. It now works like I want it to. Except for one thing.
At design time I don't know the name of the SCHEMA ID.
I have tried to pass the ID as a host variable with no luck.
I tried to create a prepared statement and using a place holder (?) for the SCHEMA ID also no luck.
Any idea how to solve my remaining conundrum?
Comment
Comment