validate an xml file against an xsd using pl sql reporting all errors and line numbers
DECLARE
l_xml_clob CLOB;
l_xsd_clob CLOB;
l_xml XMLType;
l_xsd XMLType;
l_errors XMLType;
l_error_count NUMBER;
BEGIN
-- Load XML and XSD into CLOB variables
-- Convert CLOBs to XMLType
l_xml := XMLType(l_xml_clob);
l_xsd := XMLType(l_xsd_clob);
-- Validate XML against XSD
l_errors := l_xml.schemaValidate(l_xsd);
-- Count the number of errors
l_error_count := l_errors.geterrorcount();
-- Output error details
IF l_error_count > 0 THEN
FOR i IN 1..l_error_count LOOP
DBMS_OUTPUT.put_line('Error ' || i || ':');
DBMS_OUTPUT.put_line('Line number: ' || l_errors.geterrline(i));
DBMS_OUTPUT.put_line('Error message: ' || l_errors.geterrmessage(i));
DBMS_OUTPUT.put_line('Location: ' || l_errors.geterrlocation(i));
DBMS_OUTPUT.put_line('Error code: ' || l_errors.geterrcode(i));
DBMS_OUTPUT.put_line('Severity: ' || l_errors.geterrseverity(i));
DBMS_OUTPUT.put_line('Column number: ' || l_errors.geterrcolumn(i));
DBMS_OUTPUT.put_line('Error context: ' || l_errors.geterrcontext(i));
DBMS_OUTPUT.put_line('---------------------------------');
END LOOP;
ELSE
DBMS_OUTPUT.put_line('XML is valid according to XSD.');
END IF;
END;
/
Comments
Post a Comment