User Tools

Site Tools


validating_xml_with_xsd_rpg

Validating XML with XSD (RPG)

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;

XSD with Namespace

<?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> 

<?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>

XSD without Namespace

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" version="0.1">

</xs:schema>

<?xml version="1.0" encoding="utf-8" ?>
<export xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="rpgnextgen.xsd">

</export>

validating_xml_with_xsd_rpg.txt · Last modified: 2019/01/07 08:37 by mihael