9 Replies Latest reply: Aug 15, 2013 12:19 PM by odie_63 RSS

    Exception in XMLIsValid function

    47e033bd-d313-47bd-9372-871358ce3c3e

      Hi anybody can you help me in providing the actual error whic i am geetiing while validating the xml with xsd by using XMLIsValid  function

        • 1. Re: Exception in XMLIsValid function
          odie_63

          XMLIsValid only gives a true/false status.

          Use XMLType's schemaValidate() method to get the error message.

           

          For more details, see : Transforming and Validating XMLType Data

          • 2. Re: Exception in XMLIsValid function
            47e033bd-d313-47bd-9372-871358ce3c3e

            Hi thanks for your replyy

             

            select  xmlroot((xmlelement("domaintest:DomainTables",xmlattributes('http://www.w3.org/2001/XMLSchema' as "xmlns:xsi",

            'http://www.example.com/DOMAINTEST' as "xmlns:domaintest",

            'http://www.example.com/DOMAINTEST

            http://www.example.com/schemas/domaintest.xsd' as "xsi:schemaLocation"),

            xmlelement("DomainTables",Division_var,Gender_var,BrandIS_var,size_var,class_var,print_var,sleevelength_var,

            neck_var,fit_var,leg_var,closure_var,silhouette_var,season_var,colour_var))),VERSION'1.0') into result1

            from dual;

             

             

            select XMLisValid(xmltype(result1.getClobVal()),'http://www.example.com/schemas/domaintest.xsd') into Validation_Check

            from dual;

            dbms_output.put_line(Validation_Check);

            end;

            /

             

            pasted my code if i want to pop up the error wats needs to be done

            please help me

            • 3. Re: Exception in XMLIsValid function
              47e033bd-d313-47bd-9372-871358ce3c3e

              providing u the complete query

               

               

              declare

              Division_var xmltype;

              Gender_var xmltype;

              BrandIS_var xmltype;

              size_var xmltype;

              class_var xmltype;

              print_var xmltype;

              sleevelength_var xmltype;

              neck_var xmltype;

              fit_var xmltype;

              leg_var xmltype;

              closure_var xmltype;

              silhouette_var xmltype;

              season_var xmltype;

              colour_var xmltype;

              result1 xmltype;

              Validation_Check number;

               

               

              Cursor cur_Division is

              select xmlagg(XMLELEMENT("DomainTable",xmlforest('Division' "DomainTableType",di.division "Code",di.div_name "Description")))

              from division di;

              cursor cur_gender is

              select xmlagg(XMLELEMENT("DomainTable",

              (xmlforest('Gender' "DomainTableType", gr.group_no "Code",gr.group_name "Description")))) from groups gr;

               

               

              cursor cur_brand is

              select xmlagg(XMLELEMENT("DomainTable",

              (xmlforest(DomainTableType "DomainTableType",code "Code",Description "Description")))) from(

              select distinct 'Brand IS' DomainTableType,uil.uda_value code,uv.uda_value_desc Description

              from uda_item_lov uil,uda_values uv  where uil.uda_id='8' and uv.uda_id='8' and uil.uda_value= uv.uda_value);

               

               

              cursor cur_size is

              select xmlagg(XMLELEMENT("DomainTable",

              (xmlforest('Size Group Description' "DomainTableType",dgh.diff_group_id "Code",dgh.diff_group_desc "Description"))))

              from diff_group_head dgh where diff_type='C';

               

               

              cursor cur_classDesc is

              select xmlagg(XMLELEMENT("DomainTable",

              (xmlforest('Class Description' "DomainTableType",cs.class "Code",cs.class_name "Description")))) from class cs;

               

               

              cursor cur_print is

              select xmlagg(XMLELEMENT("DomainTable",

              (xmlforest(DomainTableType "DomainTableType" ,code "Code",Description "Description")))) from(

              select distinct 'Print' DomainTableType,uil.uda_value code,uv.uda_value_desc Description

              from uda_item_lov uil,uda_values uv  where uil.uda_id='16' and uv.uda_id='16' and uil.uda_value= uv.uda_value);

               

               

              cursor cur_sleevelength is

              select xmlagg(XMLELEMENT("DomainTable",

              (xmlforest(DomainTableType "DomainTableType",code "Code",Description "Description")))) from(

              select distinct 'Sleevelength' DomainTableType,uil.uda_value code,uv.uda_value_desc Description

              from uda_item_lov uil,uda_values uv  where uil.uda_id='18' and uv.uda_id='18' and uil.uda_value= uv.uda_value);

               

               

              cursor cur_neck is

              select xmlagg(XMLELEMENT("DomainTable",

              (xmlforest(DomainTableType "DomainTableType",code "Code",Description "Description")))) from(

              select distinct 'Neck' DomainTableType,uil.uda_value code,uv.uda_value_desc Description

              from uda_item_lov uil,uda_values uv  where uil.uda_id='19' and uv.uda_id='19' and uil.uda_value= uv.uda_value);

               

               

              cursor cur_fit is

              select xmlagg(XMLELEMENT("DomainTable",

              (xmlforest(DomainTableType "DomainTableType",code "Code",Description "Description")))) from(

              select distinct 'Fit' DomainTableType,uil.uda_value code,uv.uda_value_desc Description

              from uda_item_lov uil,uda_values uv  where uil.uda_id='15' and uv.uda_id='15' and uil.uda_value= uv.uda_value);

               

               

              cursor cur_leg is

              select xmlagg(XMLELEMENT("DomainTable",

              (xmlforest(DomainTableType "DomainTableType",code "Code",Description "Description")))) from(

              select distinct 'Leg' DomainTableType,uil.uda_value Code,uv.uda_value_desc Description

              from uda_item_lov uil,uda_values uv  where uil.uda_id='21' and uv.uda_id='21' and uil.uda_value= uv.uda_value);

               

               

              cursor cur_closure is

              select xmlagg(XMLELEMENT("DomainTable",

              (xmlforest(DomainTableType "DomainTableType",code "Code",Description "Description")))) from(

              select distinct 'Clouser(aka fastening)' DomainTableType,uil.uda_value code,uv.uda_value_desc Description

              from uda_item_lov uil,uda_values uv  where uil.uda_id='20' and uv.uda_id='20' and uil.uda_value= uv.uda_value);

               

               

              cursor cur_Silhouette is

              select xmlagg(XMLELEMENT("DomainTable",

              (xmlforest(DomainTableType "DomainTableType",code "Code",Description "Description")))) from(

              select distinct 'Silhouette' DomainTableType,uil.uda_value code,uv.uda_value_desc Description

              from uda_item_lov uil,uda_values uv  where uil.uda_id='1' and uv.uda_id='1' and uil.uda_value= uv.uda_value);

               

               

              cursor cur_season is

              select xmlagg(XMLELEMENT("DomainTable",

              (xmlforest('Season' "DomainTableType",sn.season_id "Code",sn.season_desc "Description")))) from seasons sn;

               

               

              cursor cur_colour is

              select xmlagg(XMLELEMENT("DomainTable",

              (xmlforest('Color Name' "DomainTableType",di.diff_id "Code",di.diff_desc "Description"))))from diff_ids di where diff_type='C';

               

               

              begin

              open cur_Division;

              fetch cur_Division into Division_var;

              close cur_Division;

              open cur_gender;

              fetch cur_gender into Gender_var;

              close cur_gender;

              open cur_brand;

              fetch cur_brand into BrandIS_var;

              close cur_brand;

              open cur_size;

              fetch cur_size into size_var;

              close cur_size;

              open cur_classDesc;

              fetch cur_classDesc into class_var;

              close cur_classDesc;

              open cur_print;

              fetch cur_print into print_var;

              close cur_print;

              open cur_sleevelength;

              fetch cur_sleevelength into sleevelength_var;

              close cur_sleevelength;

              open cur_neck;

              fetch cur_neck into neck_var;

              close cur_neck;

              open cur_fit;

              fetch cur_fit into fit_var;

              close cur_fit;

              open cur_leg;

              fetch cur_leg into leg_var;

              close cur_leg;

              open cur_closure;

              fetch cur_closure into closure_var;

              close cur_closure;

              open cur_Silhouette;

              fetch cur_Silhouette  into silhouette_var;

              close cur_Silhouette;

              open cur_season;

              fetch cur_season into season_var;

              close cur_season;

              open cur_colour;

              fetch cur_colour into colour_var;

              close cur_colour;

               

               

              select  xmlroot((xmlelement("domaintest:DomainTables",xmlattributes('http://www.w3.org/2001/XMLSchema' as "xmlns:xsi",

              'http://www.example.com/DOMAINTEST' as "xmlns:domaintest",

              'http://www.example.com/DOMAINTEST

              http://www.example.com/schemas/domaintest.xsd' as "xsi:schemaLocation"),

              xmlelement("DomainTables",Division_var,Gender_var,BrandIS_var,size_var,class_var,print_var,sleevelength_var,

              neck_var,fit_var,leg_var,closure_var,silhouette_var,season_var,colour_var))),VERSION'1.0') into result1

              from dual;

               

               

              select XMLisValid(xmltype(result1.getClobVal()),'http://www.example.com/schemas/domaintest.xsd') into Validation_Check

              from dual;

              --dbms_output.put_line(result1.getClobVal());

              dbms_output.put_line(Validation_Check);

              end;

              /

              set serveroutput on;

              • 4. Re: Exception in XMLIsValid function
                47e033bd-d313-47bd-9372-871358ce3c3e

                hi i want to know while validation which line s making error in xml

                • 5. Re: Exception in XMLIsValid function
                  odie_63

                  You apparently read my previous reply since you've marked it helpful so, as said, use schemaValidate() method.

                  If the input XML document is not valid, it'll raise an exception and give you the error message.

                   

                  result1.schemaValidate('http://www.example.com/schemas/domaintest.xsd');

                   

                  Note that you can omit the URL parameter if you've registered the schema at the exact location specified in the xsi:schemaLocation attribute.

                  • 6. Re: Exception in XMLIsValid function
                    47e033bd-d313-47bd-9372-871358ce3c3e

                    hi  i tried the above but it is showing wrong number of types of parameters

                    could you please hlp me

                    • 7. Re: Exception in XMLIsValid function
                      odie_63

                      Could you show your code ?

                       

                      Thanks.

                      • 8. Re: Exception in XMLIsValid function
                        47e033bd-d313-47bd-9372-871358ce3c3e

                        declare

                        Division_var xmltype;

                        result1 xmltype;

                        schema_chk number;

                        doc  DBMS_XMLDOM.DOMDocument;

                        Cursor cur_Division is

                        select xmlagg(XMLELEMENT("DomainTable",xmlforest('Division' "DomainTableType",di.division "Code",di.div_name "Description")))

                        from division di;

                        begin

                        open cur_Division;

                        fetch cur_Division into Division_var;

                        close cur_Division;

                        select  xmlroot((xmlelement("domaintest:DomainTables",xmlattributes('http://www.w3.org/2001/XMLSchema' as "xmlns:xsi",

                        'http://www.example.com/DOMAINTEST' as "xmlns:domaintest",

                        'http://www.example.com/DOMAINTEST

                        http://www.example.com/schemas/domaintest.xsd' as "xsi:schemaLocation"),

                        xmlelement("DomainTables",Division_var))),VERSION'1.0') into result1

                        from dual;

                        commit;

                        --insert into adsm_domain values (result1);

                        --select result1.SchemaValidate('http://www.example.com/schemas/domaintest.xsd') into schema_chk from dual;

                        XMLTYPE.SchemaValidate(result1);

                        --result1.isSchemaValid('http://www.example.com/schemas/domaintest.xsd');

                        --dbms_output.put_line(schema_chk);

                        end;

                        /

                         

                         

                         

                        Now its showing method invalid for non schema based documents

                        • 9. Re: Exception in XMLIsValid function
                          odie_63

                          Sorry, I mixed up the createSchemaBasedXML() syntax with schemaValidate() in my previous example.


                          First of all, you have to correct the xsi prefix definition, it should be :

                          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"


                          This should be OK now :

                          select xmlroot( ... )

                          into result1

                          from dual;

                           

                          result1 := result1.createSchemaBasedXML('http://www.example.com/schemas/domaintest.xsd');

                          result1.schemaValidate();

                           

                          Please also note that, normally, if all xsi attributes are defined correctly and the schema registered at the specified location, you can omit the createSchemaBasedXML step.

                          But apparently, XMLRoot() is messing up the schema-based state.