我只有一行带有带有HTML标签的文本。例。
html_string = '<!DOCTYPE html><html><body> <h1> My First Heading</h1> <p> My first paragraph.</p> </body> </html> '.
我想将html_string的值作为格式化的HTML文本返回:
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
最好出现在一个弹出窗口中。有人知道吗?最好是功能模块左右。我已经寻找了一段时间,但没有找到符合我要求的东西。
答案 0 :(得分:2)
我恰好找到了我所需要的。这可能对将来的程序员有帮助:
https://help.sap.com/doc/abapdocu_750_index_htm/7.50/de-DE/abenstring_function_escape_abexa.htm
REPORT demo_escape_html.
CLASS demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS main.
ENDCLASS.
CLASS demo IMPLEMENTATION.
METHOD main.
DATA: body TYPE string,
esc_body TYPE string.
body = `<table border> `
&& `<tr><td>11</td><td>12</td></tr> `
&& `<tr><td>21</td><td>22</td></tr> `
&& `</table>`.
esc_body = escape( val = body
format = cl_abap_format=>e_html_text ).
cl_demo_output=>new(
)->begin_section( 'Original text'
)->write_text( body
)->next_section( 'Original text formatted as HTML'
)->write_html( body
)->next_section( 'Escaped text'
)->write_text( esc_body
)->next_section( 'Escaped text formatted as HTML'
)->write_html( esc_body
)->display( ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
demo=>main( ).
答案 1 :(得分:1)
如果HTML是XHTML(与XML兼容),则可以像显示其他任何XML一样显示它,并且集成的Windows浏览器将自动缩进XML级别:
DATA l_xml TYPE string.
cl_abap_browser=>show_xml( xml_string = l_xml title = 'text' ).
如果HTML不是XHTML,则没有SAP程序可以解释“开始”标签(例如<br>
,<li>
等)