5 Replies Latest reply: Sep 24, 2012 4:09 AM by user640107 RSS

    validation against schema not in xml db

    user640107
      Hi,

      It may be that I'm going blind but I can find no way to validate a document against a schema without first registering the schema in xml db.

      For my purposes xml db introduces an unnecessary layer of complexity and management and my desire is to use an xmltype method like (my fictitious method) validatesAgainstSchema as follows:

      declare
      v_doc xmltype := xmltype('my document xml');
      v_schema xmltype := xmltype('my schema document xml');
      begin
      if v_doc.validatesAgainstSchema(vschema) = true then
      ..... do some stuff
      else
      .....throw some error
      end if;
      end;
      /

      If anyone has any clever tricks that will allow me to achieve this please let me know

      thanks in advance

      Edited by: user640107 on Sep 23, 2012 8:08 AM
        • 1. Re: validation against schema not in xml db
          odie_63
          Hi,
          It may be that I'm going blind but I can find no way to validate a document against a schema without first registering the schema in xml db.
          If you want to use the validation features of XML DB (via XMLType's corresponding methods), the schema has to be registered first, there's no way around that.

          Without registering, the alternative is to use an external validation tool you can interface with the database via a PL/SQL API.
          The usual example is the Java schema processor :
          http://docs.oracle.com/cd/E11882_01/appdev.112/e23582/adx_j_sproc.htm#i1003036
          For my purposes xml db introduces an unnecessary layer of complexity and management
          Sorry, what "complexity" are you talking about?

          Where's the difficulty in calling DBMS_XMLSCHEMA.REGISTERSCHEMA?
          You just have to do it once, with genTypes and genTables parameters set to false, and there you go, you can use the functionalities.

          If the schema evolves, then just delete the existing one and re-register the new version. It only takes a couple of procedure calls.
          • 2. Re: validation against schema not in xml db
            user640107
            thanks odie,

            Regarding your "complex" observation. At a general level I suppose the term is subjective.

            The reason for my comment however is that we work a lot with schemas and the example code I have provided is simple and flexible for many purposes including just testing xml related stuff on the fly - and in my personal opinion PL/SQL really should support the capability.

            thanks again
            • 3. Re: validation against schema not in xml db
              user640107
              In working on this example I have thought of a few more reasons to call it complex

              1. once the schema has been registered, if the transaction subsequently fails the schema persists
              2. because the schema is stored in the xmldb it means that this area then needs to be backed up also
              3. if the xml schemas exist in xml db and I remove my personal schema , the xml db schemas need to be explicitly purged otherwise they persist

              I absolutely know there is value in the XML DB but I do think that adding this conceptually simple XML validation method to the XMLtype would open up a developer's options significantly ito the use of schemas in the db, as suddenly:

              1. in-proc stored schema document validations become possible
              2. in-table stored schema document validations become possible
              3. xml db schema validations obviously remain possible

              hope this explains my thoughts a bit more comprehensively
              • 4. Re: validation against schema not in xml db
                odie_63
                1. once the schema has been registered, if the transaction subsequently fails the schema persists
                Easily managed with a conditional statement, or a proper exception handler.
                2. because the schema is stored in the xmldb it means that this area then needs to be backed up also
                XML DB is not a separate part of the database, it's getting backed up like any other data - but depends on what you mean by "backed up".
                3. if the xml schemas exist in xml db and I remove my personal schema , the xml db schemas need to be explicitly purged otherwise they persist
                XML DB has versioning capabilities, and you can also register the same schemas multiple times using different URLs.

                hope this explains my thoughts a bit more comprehensively
                Sure :)
                I understand you're more looking for some kind of one-shot validation functionality, where schemas can change ad libitum.
                That's typically the purpose of an external tool then.
                • 5. Re: validation against schema not in xml db
                  user640107
                  :) thanks - while I agree with all your comments as options I have available, the single validation method

                  isValidBoo := myXMLdoc.validateAgainstSchema(myXMLschemaDoc);

                  would be way the quickest, cleanest and most appropriate solution for what I am trying to achieve, and I believe it opens up nice options for XML validation to developers

                  So come on Oracle - as schema validation functionality exists in oracle already via XML DB adding a new "validate using schema( schemaDoc XMLtype)" method to XMLtype surely shouldn't be too difficult???