1 Reply Latest reply: Aug 9, 2012 4:54 AM by odie_63 RSS

    validate xml againt registerd schema, ignoring xsi:noNamespaceSchemaLocatio

    919560
      hi,

      i would like to validate received xml against registered schema, ignoring the one defined in xml. I use XMLisValid(xml_data ,schema_url) but it works only if there is no xsi:noNamespaceSchemaLocation attrubute.

      This is sample xml.

      <?xml version="1.0" encoding="UTF-8"?>
      <!--Sample XML file generated by XMLSPY v2004 rel. 3 U (http://www.xmlspy.com)-->
      <ROOT xmlns:xdb="http://xmlns.oracle.com/xdb" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://localhost/public/xsd/myapp.xsd">
           <ID>0</ID>
           <INFO>
                <INFO_ID>0</INFO_ID>
                <INFO_CONTENT>Text</INFO_CONTENT>
           </INFO>
      </ROOT>

      Anybody knows if it is possible?

      Thanks in advance..
        • 1. Re: validate xml againt registerd schema, ignoring xsi:noNamespaceSchemaLocatio
          odie_63
          Hi,

          It should work according to the documentation, but obviously it doesn't.
          So I guess you'll have to consider one of these options :

          - Changing the xsi:noNamespaceSchemaLocation at the source to use the URL of your registered schema instead
          - The other way around : register your schema at the URL defined in the document
          - Removing the xsi:noNamespaceSchemaLocation attribute prior to validation

          Here's an example for the third option :
          BEGIN
            dbms_xmlschema.registerSchema(
              schemaURL => 'myapp2.xsd'
            , schemaDoc => 
          '<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
            <xs:element name="ROOT">
              <xs:complexType>
                <xs:sequence>
                  <xs:element name="ID" type="xs:integer"/>
                  <xs:element name="INFO">
                    <xs:complexType>
                      <xs:sequence>
                        <xs:element name="INFO_ID" type="xs:integer"/>
                        <xs:element name="INFO_CONTENT" type="xs:string"/>
                      </xs:sequence>
                    </xs:complexType>
                  </xs:element>
                </xs:sequence>
              </xs:complexType>
            </xs:element>
          </xs:schema>'
            , local => true
            , genTypes => false
            , genTables => false
            );
          END;
          / 
          
          
          SQL> declare
            2  
            3    doc xmltype := xmltype('<?xml version="1.0" encoding="UTF-8"?>
            4  <ROOT xmlns:xdb="http://xmlns.oracle.com/xdb"
            5        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            6        xsi:noNamespaceSchemaLocation="http://localhost/public/xsd/myapp.xsd">
            7  <ID>0</ID>
            8  <INFO>
            9  <INFO_ID>0</INFO_ID>
           10  <INFO_CONTENT>Text</INFO_CONTENT>
           11  </INFO>
           12  </ROOT>');
           13  
           14    isValid integer;
           15  
           16  begin
           17  
           18    doc := doc.deleteXML('/ROOT/@xsi:noNamespaceSchemaLocation','xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"');
           19  
           20    select xmlisvalid(doc, 'myapp2.xsd') into isValid from dual;
           21  
           22    dbms_output.put_line('isValid = '||to_char(isValid));
           23  
           24  end;
           25  /
           
          isValid = 1
           
          PL/SQL procedure successfully completed