16.4 HTML_ATTRIBUTE Function

Use this function to escape the values of HTML entity attributes. It hex escapes everything that is not alphanumeric or in one of the following characters:

  • ,
  • .
  • -
  • _

Syntax

APEX_ESCAPE.HTML_ATTRIBUTE (
    p_string IN VARCHAR2 )
    return VARCHAR2;

Parameters

Table 16-4 HTML_ATTRIBUTE Function Parameters

Parameter Description

p_string

The text string that is escaped.

Example

This example generates a HTML list of of titles and text bodies. HTML entity attributes are escaped with HTML_ATTRIBUTE, whereas normal text is escaped with HTML and HTML_TRUNC.

BEGIN 
    htp.p('<ul>'); 
    for l_data in ( select title, cls, body 
        from my_topics ) 
    LOOP 
    sys.htp.p('<li><span class="'||
        apex_escape.html_attribute(l_data.cls)||'">'|| 
        apex_escape.html(l_data.title)||'</span>'); 
    sys.htp.p(apex_escape.html_trunc(l_data.body)); 
    sys.htp.p('</li>'); 
    END LOOP; 
    htp.p('</ul>'); 
END;