XML error 9082

skunal

Member
I want to catch the error in XML. When there is opening root tag but not closing one .......Example :- I have XML " <abc><xyz></xyz>" . Here there is no closing tag ... So when i write the code
Code:
DEF VAR hDoc AS HANDLE NO-UNDO.
DEF VAR hRoot AS HANDLE NO-UNDO.
DEF VAR good AS LOGICAL NO-UNDO.
DEF VAR cXML AS LONGCHAR NO-UNDO.
ASSIGN cXML = [B]"<?xml version='1.0' encoding='UTF-8'?>
<retConsStatServ xmlns='http://www.portalfiscal.inf.br/nfe' versao='1.07'>
<tpAmb>2</tpAmb>
<verAplic>SP_NFE_PL_005a_R01</verAplic>
<cStat>107</cStat>
<xMotivo>Serviço em Operação</xMotivo>
<cUF>35</cUF>
<dhRecbto>2008-06-14T12:07:48</dhRecbto>
<tMed>1</tMed>"    --- THIS XML has no closing[COLOR=#ff0000] </retConsStatServ>[/COLOR] tag which is Root tag

[/B]CREATE X-DOCUMENT hDoc.
CREATE X-NODEREF hRoot.
[B]hDoc:LOAD("LONGCHAR",Cxml,FALSE[/B]).   ---- This give me error [B]9082 --- closing tag not found......

So i gave  
  [B]hDoc:LOAD("LONGCHAR",Cxml,FALSE[/B])  No-error.

And checked with 
   if ERROR-STATUS:ERROR then
     message "invalid XML" view-as alert-box.

          BUT this error checking is not working as ERROR-STATUS is always returning NO in case of correct XML as well as ERROR XML.
      
[/B]...

Can Anyone please let me know how to handle this error.
 

Stefan

Well-Known Member
The LOAD method returns true / false if it is successful / fails.

Code:
DEF VAR lok AS LOGICAL NO-UNDO.

ASSIGN lok = hdoc:LOAD( "LONGCHAR":U, cxml, FALSE ) NO-ERROR.

MESSAGE lok VIEW-AS ALERT-BOX.

If you are on at least 10.1C or so you can also CATCH the error.

Code:
DO ON ERROR UNDO, LEAVE:


   hDoc:LOAD( "LONGCHAR":U, cxml, FALSE ). 


   CATCH oe AS progress.lang.error:


      MESSAGE oe:getMessage(1) VIEW-AS ALERT-BOX.


   END CATCH.


END.
 
Top