5 Replies Latest reply: Aug 24, 2012 6:16 AM by Ric79 RSS

    DTD validation

    Ric79
      Hi all,
      basically I have the same need of how to add namespace to DTD

      MeasDataCollection.dtd
      <?xml version="1.0" encoding="UTF-8"?>
      <!ELEMENT mdc (mfh, md*, mff)>
      <!ELEMENT mfh (ffv, sn, st, vn, cbt)>
      <!ELEMENT md (neid, mi*)>
      <!ELEMENT neid (neun, nedn, nesw?)>
      <!ELEMENT mi (mts, jobid?, gp, rp?, mt*, mv*)>
      <!ELEMENT mv (moid, r*, sf?)>
      <!ELEMENT mff (ts)>
      <!ELEMENT jobid (#PCDATA)>
      <!ELEMENT rp (#PCDATA)>
      <!ELEMENT ts (#PCDATA)>
      <!ELEMENT sf (#PCDATA)>
      <!ELEMENT r (#PCDATA)>
      <!ATTLIST r p CDATA "">
      <!ELEMENT mt (#PCDATA)>
      <!ATTLIST mt p CDATA "">
      <!ELEMENT moid (#PCDATA)>
      <!ELEMENT gp (#PCDATA)>
      <!ELEMENT mts (#PCDATA)>
      <!ELEMENT nedn (#PCDATA)>
      <!ELEMENT neun (#PCDATA)>
      <!ELEMENT nesw (#PCDATA)>
      <!ELEMENT cbt (#PCDATA)>
      <!ELEMENT vn (#PCDATA)>
      <!ELEMENT st (#PCDATA)>
      <!ELEMENT sn (#PCDATA)>
      <!ELEMENT ffv (#PCDATA)>
      <!-- end of MeasDataCollection.dtd -->
      An example of XML file ( TESTFILE.XML ):
      <?xml version="1.0"?>
      <?xml-stylesheet type="text/xsl" href="MeasDataCollection.xsl" ?>
      <!DOCTYPE mdc SYSTEM "MeasDataCollection.dtd">
      <mdc xmlns:HTML="http://www.w3.org/TR/REC-xml">
       <mfh>
        <ffv>1</ffv>
        <sn>DC=XXXX</sn>
        <st>XXX</st>
        <vn>XXXX</vn>
        <cbt>20120821131500.0+0200</cbt>
       </mfh>
       <md>
        <neid>
         <neun></neun>
         <nedn>XXXX</nedn>
        </neid>
        <mi>
         <mts>20120821133000.0+0200</mts>
         <gp>900</gp>
         <mt>COL1</mt>
         <mt>COL2</mt>
         <mt>COL3</mt>
         <mv>
           <moid>AAA</moid>
           <r>1.33</r>
           <r>1.57</r>
           <r>1624819.0</r>
         <sf>FALSE</sf>
         </mv>
         <mv>
           <moid>BBB</moid>
           <r>2.40</r>
           <r>13.98</r>
           <r>1396601.4</r>
         </mv>
        </mi>
       </md>
       <mff>
         <ts>20120821133000.0+0200</ts>
       </mff>
      </mdc>
      Here there is my code
      DECLARE
         V_RESULT   BOOLEAN;
      BEGIN
         V_RESULT   := DBMS_XDB.CREATERESOURCE('/MeasDataCollection.dtd', BFILENAME('MYDIR', 'MeasDataCollection.dtd'));
      END;
      /
      
      CREATE TABLE MYTABLE
      (
         FILE_NAME   VARCHAR2(256),
         XML_DOC_B   XMLTYPE
      )
      TABLESPACE TBS_CK6EPM1_S
      XMLTYPE COLUMN XML_DOC_B STORE AS CLOB;
      /
      
      INSERT INTO CKGNT_XML_LOADING(FILE_NAME, XML_DOC_B)
           VALUES ('TESTFILE.XML', XMLTYPE(BFILENAME('MYDIR', 'TESTFILE.XML'), NLS_CHARSET_ID('UTF-8')));
      ORA-31011: XML parsing failed
      ORA-19202: Error occurred in XML processing
      LPX-00106: Warning: attribute "xmlns:HTML" of element "mdc" is undefined
      Error at line 4
      ORA-06512: at "SYS.XMLTYPE", line 296
      ORA-06512: at line 1
      How to solve the error?

      Riccardo
        • 1. Re: DTD validation
          Ric79
          I found that
          alter session set events ='31156 trace name context forever, level 2';
          skip the DTD validation. Is there a better solution for 11.2g?

          Riccardo
          • 2. Re: DTD validation
            odie_63
            Yes, you can use the event.

            If you prefer keeping DTD validation, you can add this :
            <!ELEMENT mdc (mfh, md*, mff)>
            <!ATTLIST mdc xmlns:HTML CDATA #FIXED "http://www.w3.org/TR/REC-xml">
            ...
            • 3. Re: DTD validation
              Ric79
              Hi odie,
              with your solution when I try to execute
              SELECT X0.*
                FROM MYTABLE T,
                     XMLTABLE('/mdc/mfh'
                              PASSING T.XML_DOC_B
                              COLUMNS C_B_T VARCHAR2(1000) PATH 'cbt') X0
               WHERE T.FILE_NAME = 'TESTFILE.XML'
              
              ORA-31011: XML parsing failed
              ORA-19202: Error occurred in XML processing
              LPX-00107: Warning: element "mdc" has multiple declarations
              Error at line 30
              Error at line 2
              With my solution, everything is fine.

              Why?
              • 4. Re: DTD validation
                odie_63
                Bug?

                {thread:id=2393051}
                • 5. Re: DTD validation
                  Ric79
                  Ok, according that thread it seems a bug.

                  I don't want to switch to binary storage (there is no DTD validation with binary, isn't it?).

                  I prefer use clob storage and make alter system...