Validate XML with XSD file using SaxReader OE 11.6

Posted by atuldalvi123 on 22-Aug-2017 05:49

Hi All,

I have to validate my xml file with a given XSD file and for that I am using SaxReader with attribute  hParser:NONAMESPACE-SCHEMA-LOCATION = "c:\abc.xsd"  and hParser:VALIDATION-ENABLED = TRUE.

My xsd file is not correct, even if it is complete garbage it wont give me a error message.

I added  error callback and also  SAX-PARSE() in a persistent procedure but still i get no errors.

Pls suggest.

All Replies

Posted by Robin Brown on 22-Aug-2017 10:01

Please log a bug for this.  I was able to get to an error using x-document:load(), but not with sax-parse().  We'd need to debug the situation.

Regards,

Robin

Posted by atuldalvi123 on 22-Aug-2017 23:41

hDoc:load() validates only XML file structure, not against external XSD file. I also tried below options but still no success.

hDoc:SCHEMA-PATH = "validate.xsd".

hDoc:NONAMESPACE-SCHEMA-LOCATION = "validate.xsd".

I tried these options for Sax reader as well but getting same result.

Is there any other way to validate XML file against the external XSD file ?

Posted by marian.edu on 23-Aug-2017 01:08

You need to enable validation by setting VALIDATION-ENABLED = true, not sure about xDoc but that works for SAX reader.


Marian Edu

Acorn IT 
+40 740 036 212

Posted by atuldalvi123 on 23-Aug-2017 01:22

I tried that too as below but still not validating.

CREATE SAX-READER hParser.

RUN Service\ParseXML.p PERSISTENT SET hCallbacks.

hParser:HANDLER = hCallbacks.

hParser:SET-INPUT-SOURCE("FILE", "validate.xml").

hParser:VALIDATION-ENABLED = TRUE . /* no dtd validation, only XSD */

hParser:NONAMESPACE-SCHEMA-LOCATION = "validate.xsd".

hParser:SCHEMA-PATH = "validate.xsd".

hParser:SAX-PARSE-FIRST() NO-ERROR.

REPEAT WHILE hParser:PARSE-STATUS = SAX-RUNNING:

 hParser:SAX-PARSE-NEXT() NO-ERROR.

END.

CASE hParser:PARSE-STATUS :

   WHEN SAX-COMPLETE THEN DO :  

       MESSAGE "sax parser complete" VIEW-AS ALERT-BOX.

   END.

   WHEN SAX-PARSER-ERROR THEN DO :

       MESSAGE "sax parser error" VIEW-AS ALERT-BOX.

   END.

   OTHERWISE DO :

       MESSAGE "Unknown status" VIEW-AS ALERT-BOX.

   END.

END CASE.

IF ERROR-STATUS:ERROR THEN          

DO:                                  

   IF ERROR-STATUS:NUM-MESSAGES > 0 THEN

   MESSAGE ERROR-STATUS:GET-MESSAGE(1) VIEW-AS ALERT-BOX.

ELSE                                                  

   MESSAGE RETURN-VALUE VIEW-AS ALERT-BOX.

END.

ELSE

   MESSAGE "Document parsed successfully" VIEW-AS ALERT-BOX.

DELETE OBJECT hParser.

DELETE PROCEDURE hCallbacks.

Posted by marian.edu on 23-Aug-2017 01:40

I think validation errors are seen more like warnings, might worth checking error-status:num-messages even if error-status:error equals false… otherwise add ‘Error’ and ‘FatalError’ procedures in your callback handler (hCallbacks), both takes error message as input (character) and see if that catches the validation errors.



Marian Edu

Acorn IT 
+40 740 036 212

Posted by atuldalvi123 on 23-Aug-2017 01:55

Yes, I tried that too but still I am not able to catch the error. Actually I am following below sample example provided by progress.

knowledgebase.progress.com/.../P157414

With ERROR-STATUS:ERROR EQ FALSE it is showing 0 num-messages.

Posted by Robin Brown on 23-Aug-2017 08:38

hDoc:Load() is supposed to validate the XML document against any .xsd specified with SCHEMA-LOCATION, NONAMSPACE-SCHEMA-LOCATION.  As I said previously, please log a bug.  Thanks.

This thread is closed