Differences

This shows you the differences between two versions of the page.

Link to this comparison view

validating_xml_with_xsd_rpg [2019/01/07 09:37]
validating_xml_with_xsd_rpg [2021/04/05 11:23] (current)
Line 1: Line 1:
 +====== Validating XML with XSD (RPG) ======
  
 +
 +<sxh>
 +dcl-proc main;
 +
 +  dcl-s filepath char(1024);
 +  dcl-s domEnvData pointer inz(%addr(Qxml_DOMEXCDATA));
 +  dcl-s parser pointer;
 +
 +  filepath = '/usr/local/example/xmlvalid/data.xml' + null;
 +
 +  // Initialize the XML environment, provide pointer to DOM exception
 +  // data area. A call to QxmlInit must occur before any other API call.
 +  QxmlInit(domEnvData);
 +
 +  // Create a new parser instance
 +  parser = QxmlXercesDOMParser_new(domEnvData);
 +
 +  // Configure parser
 +  QxmlXercesDOMParser_setValidationScheme(parser : Qxml_VALAU);
 +  QxmlXercesDOMParser_setDoNamespaces(parser : true);
 +  QxmlXercesDOMParser_setDoSchema(parser : true);
 +  QxmlXercesDOMParser_setValidationSchemaFullChecking(parser : true);
 +
 +  // Parse xml file
 +  QxmlXercesDOMParser_parse_SystemId(parser :%addr(filePath) : Qxml_JOBCCSID : 0);
 +
 +  // Check for parse error
 +  if (Qxml_DOMRTNCOD = Qxml_DOMNOERROR);
 +    message_info('XML Dokument entspricht dem XML Schema.');
 +  else;
 +    message_info(Qxml_RESERVE);
 +  endif;
 +
 +end-proc;
 +</sxh>
 +
 +
 +===== XSD with Namespace =====
 +
 +<sxh xml>
 +<?xml version="1.0"?>
 +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
 + targetNamespace="https://rpgnextgen.com" xmlns="https://rpgnextgen.com"
 + elementFormDefault="qualified">
 +
 +    <!-- scheme description -->
 +
 +</xs:schema> 
 +</sxh>
 +
 +<sxh xml>
 +<?xml version="1.0"?>
 +
 +<daten xmlns="https://rpgnextgen.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 + xsi:schemaLocation="https://rpgnextgen.com rpgnextgen.xsd">
 +
 +</daten>
 +</sxh>
 +
 +
 +===== XSD without Namespace =====
 +
 +<sxh xml>
 +<?xml version="1.0" encoding="utf-8" ?>
 +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" version="0.1">
 +
 +</xs:schema>
 +</sxh>
 +
 +
 +<sxh xml>
 +<?xml version="1.0" encoding="utf-8" ?>
 +<export xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="rpgnextgen.xsd">
 +
 +</export>
 +</sxh>
 +
 +
 +{{tag>devel ibm rpg xml}}