4 Replies Latest reply on Jul 30, 2007 2:07 PM by mdrake-Oracle

    using & within an attribute

    590257
      Hi
      Is there any way i can use & within the value of an attribute
      as
      <book title="HP7" Auther ="JKR" and Desc = "Interesting & good" />
      I dont want to use &amp;amp; (Ampersand amp ;) here .
      is there any way to use <![CDATA[..]]> to enclose this attribute
      or can i specify the same in dtd , when i use CDATA in ATTLIST for this attribute my xmlparsefile (function in c) fails giving 00242 error.
      any help is appreciated .
      Thanks

      Message was edited by:
      user587254
        • 1. Re: using & within an attribute
          mdrake-Oracle
          Not if you want to have legal XML .... Not on oracle problem.
          • 2. Re: using & within an attribute
            MichaelS
            Looks like you can generate this xml without problems:
            michaels>  set define off
            
            michaels>  declare
               ctx   dbms_xmlgen.ctxhandle;
               xml   xmltype;
            begin
               ctx :=
                  dbms_xmlgen.newcontext
                     ('select ''<book title="HP7" Auther="JKR" Desc="Interesting & good" />'' x from dual'
                     );
               dbms_xmlgen.setconvertspecialchars (ctx, false);
               xml := dbms_xmlgen.getxmltype (ctx);
               dbms_output.put_line (xml.getstringval ());
               dbms_xmlgen.closecontext (ctx);
            end;
            /
            <ROWSET>
             <ROW>
              <X><book title="HP7" Auther="JKR" Desc="Interesting & good" /></X>
             </ROW>
            </ROWSET>
            But then again it seems impossible to EXTRACT »Desc« attribute again:
            michaels>  declare
               ctx   dbms_xmlgen.ctxhandle;
               xml   xmltype;
            begin
               ctx :=
                  dbms_xmlgen.newcontext
                     ('select ''<book title="HP7" Auther="JKR" Desc="Interesting & good" />'' x from dual'
                     );
               dbms_xmlgen.setconvertspecialchars (ctx, false);
               xml := dbms_xmlgen.getxmltype (ctx);
               dbms_output.put_line (xml.getstringval ());
               
               dbms_output.put_line (xml.extract('//@Desc').getstringval());
               
               dbms_xmlgen.closecontext (ctx);
            end;
            /
            Error at line 4
            ORA-31011: XML parsing failed
            ORA-19202: Error occurred in XML processing
            LPX-00242: invalid use of ampersand ('&') character (use &amp;)
            Error at line 3
            ORA-06512: at "SYS.XMLTYPE", line 111
            ORA-06512: at line 13
            • 3. Re: using & within an attribute
              590257
              Ok. Thanks for the replies. it was a great help for me.
              I've one more question.

              In the DTD if i specify an attribute as CDATA, can i have & ( and also < ,> symobls) symbols in the attribute value i.e using & directly instead of using & ampp ; .
              is this valid in XML?
              'coz if i specify an attribute as CDATA and use & in the value of the attribute, my xml parser errors out,i use xmlparsefile function. Is this not valid XML or problem with the parser?


              I'd be happy ,if you could provide reasons for the same. Tried to search on the internet couldnt find any suitable links.

              Thanks
              • 4. Re: using & within an attribute
                mdrake-Oracle
                AFAIK an attribute cannot have a child node. Since CDATA is a child node the answer is no.