Created
February 27, 2021 13:05
-
-
Save sandraros/ed2808ce00af79e0762b08d9f4514942 to your computer and use it in GitHub Desktop.
Test of ABAP method skip_non_xml_characters in if_ixml_ostream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REPORT. | |
DATA l_string TYPE string. | |
DATA character2 TYPE string. | |
data(vietnamese) = 'ớắ'. | |
data(emoji) = '🦀🦀🤙🤙🤙🌎🌍🌏'. | |
PERFORM get_characters_unicode_range USING '0000' 'FFFF' CHANGING l_string. | |
DATA(off) = 0. | |
data(xml_characters) = ``. | |
data(non_xml_characters) = ``. | |
WHILE off < strlen( l_string ). | |
DATA xml_binary TYPE xstring. | |
DATA(character) = l_string+off(1). | |
PERFORM test_skip_non_xml_characters USING character CHANGING character2. | |
IF character <> character2. | |
non_xml_characters = non_xml_characters && character. | |
else. | |
xml_characters = xml_characters && character. | |
ENDIF. | |
ADD 1 TO off. | |
ENDWHILE. | |
ASSERT 1 = 1. "break-point | |
FORM get_characters_unicode_range | |
USING start_hex | |
last_hex | |
CHANGING string TYPE string. | |
DATA c1 TYPE c LENGTH 1. | |
DATA x2 TYPE x LENGTH 2. | |
DATA int TYPE i. | |
string = ``. | |
c1 = cl_abap_conv_in_ce=>uccp( start_hex ). | |
int = cl_abap_conv_out_ce=>uccpi( c1 ). | |
DO. | |
c1 = cl_abap_conv_in_ce=>uccpi( int ). | |
x2 = cl_abap_conv_out_ce=>uccp( c1 ). | |
CONCATENATE string c1 INTO string RESPECTING BLANKS. | |
IF x2 = last_hex. | |
EXIT. | |
ENDIF. | |
ADD 1 TO int. | |
ENDDO. | |
ENDFORM. | |
FORM test_skip_non_xml_characters USING input_text TYPE string CHANGING output_text TYPE string. | |
DATA xstring TYPE xstring. | |
DATA lo_ixml TYPE REF TO if_ixml. | |
DATA lo_document TYPE REF TO if_ixml_document. | |
DATA lo_root TYPE REF TO if_ixml_element. | |
DATA lo_text TYPE REF TO if_ixml_text. | |
DATA lo_stream_factory TYPE REF TO if_ixml_stream_factory. | |
DATA: lo_ostream TYPE REF TO if_ixml_ostream. | |
DATA: lo_renderer TYPE REF TO if_ixml_renderer, | |
l_rc TYPE i. | |
DATA lo_istream TYPE REF TO if_ixml_istream. | |
DATA lo_parser TYPE REF TO if_ixml_parser. | |
lo_ixml = cl_ixml=>create( ). | |
lo_document = lo_ixml->create_document( ). | |
lo_root = lo_document->create_simple_element( name = 'ROOT' parent = lo_document ). | |
lo_text = lo_document->create_text( input_text ). | |
l_rc = lo_root->append_child( lo_text ). | |
lo_stream_factory = lo_ixml->create_stream_factory( ). | |
lo_ostream = lo_stream_factory->create_ostream_xstring( string = xstring ). | |
lo_ostream->skip_non_xml_characters( ). | |
lo_renderer = lo_ixml->create_renderer( ostream = lo_ostream | |
document = lo_document ). | |
l_rc = lo_renderer->render( ). | |
lo_ixml = cl_ixml=>create( ). | |
lo_document = lo_ixml->create_document( ). | |
lo_stream_factory = lo_ixml->create_stream_factory( ). | |
lo_istream = lo_stream_factory->create_istream_xstring( xstring ). | |
lo_parser = lo_ixml->create_parser( stream_factory = lo_stream_factory | |
istream = lo_istream | |
document = lo_document ). | |
lo_parser->parse( ). | |
lo_root = lo_document->get_root_element( ). | |
output_text = lo_root->get_value( ). | |
ENDFORM. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is used to check which characters are skipped by method skip_non_xml_characters of if_ixml_ostream (list of characters in variable
non_xml_characters
), and which are not (list of characters in variablexml_characters
).Result: skipped characters are 0x0000 to 0x0008, 0x000B, 0x000C and 0x0800 to 0xDFFF.