mirror of
https://github.com/abapGit/abapGit.git
synced 2025-05-01 12:20:51 +08:00
* Leading spaces are lost when pulling bug #2571 Reason: during the pull (deserialization), the method `PARSE` of `ZCL_ABAPGIT_XML` does a `li_parser->set_normalizing( iv_normalize )` whose parameter has the default value "true", which strips leading and trailing spaces. Solution: use `li_parser->add_strip_space_element( )` instead of using the normalization, which seems to work in elementary objects (clas, devc, doma, dtel, enho, enqu, fugr, intf, prog, scp1, tabl, tran, ttyp), but I fear of side effects throughout all abapGit features. * #2571 zcl_abapgit_xml iv_normalize removed+AU - Removal of useless parameter IV_NORMALIZE of method PARSE - Abap Unit test added for testing the method PARSE for an XML valuecontaining leading and trailing spaces * renaming attribute lo_xml to mo_xml
This commit is contained in:
parent
c9609b2ac6
commit
5a6e6ee2f6
|
@ -1,13 +1,12 @@
|
|||
CLASS zcl_abapgit_xml DEFINITION
|
||||
PUBLIC
|
||||
ABSTRACT
|
||||
CREATE PUBLIC.
|
||||
CREATE PUBLIC .
|
||||
|
||||
PUBLIC SECTION.
|
||||
METHODS:
|
||||
constructor
|
||||
IMPORTING iv_filename TYPE string OPTIONAL.
|
||||
|
||||
PROTECTED SECTION.
|
||||
DATA: mi_ixml TYPE REF TO if_ixml,
|
||||
mi_xml_doc TYPE REF TO if_ixml_document,
|
||||
|
@ -24,8 +23,7 @@ CLASS zcl_abapgit_xml DEFINITION
|
|||
RETURNING VALUE(rv_xml) TYPE string.
|
||||
|
||||
METHODS parse
|
||||
IMPORTING iv_normalize TYPE abap_bool DEFAULT abap_true
|
||||
iv_xml TYPE string
|
||||
IMPORTING iv_xml TYPE string
|
||||
RAISING zcx_abapgit_exception.
|
||||
PRIVATE SECTION.
|
||||
|
||||
|
@ -39,7 +37,7 @@ ENDCLASS.
|
|||
|
||||
|
||||
|
||||
CLASS ZCL_ABAPGIT_XML IMPLEMENTATION.
|
||||
CLASS zcl_abapgit_xml IMPLEMENTATION.
|
||||
|
||||
|
||||
METHOD constructor.
|
||||
|
@ -147,7 +145,7 @@ CLASS ZCL_ABAPGIT_XML IMPLEMENTATION.
|
|||
li_parser = mi_ixml->create_parser( stream_factory = li_stream_factory
|
||||
istream = li_istream
|
||||
document = mi_xml_doc ).
|
||||
li_parser->set_normalizing( iv_normalize ).
|
||||
li_parser->add_strip_space_element( ).
|
||||
IF li_parser->parse( ) <> 0.
|
||||
error( li_parser ).
|
||||
ENDIF.
|
||||
|
|
90
src/xml/zcl_abapgit_xml.clas.testclasses.abap
Normal file
90
src/xml/zcl_abapgit_xml.clas.testclasses.abap
Normal file
|
@ -0,0 +1,90 @@
|
|||
CLASS ltcl_xml DEFINITION DEFERRED.
|
||||
|
||||
CLASS ltcl_xml_concrete DEFINITION FOR TESTING
|
||||
FINAL
|
||||
INHERITING FROM zcl_abapgit_xml
|
||||
FRIENDS ltcl_xml.
|
||||
ENDCLASS.
|
||||
|
||||
CLASS ltcl_xml_concrete IMPLEMENTATION.
|
||||
ENDCLASS.
|
||||
|
||||
CLASS ltcl_xml DEFINITION FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
|
||||
|
||||
PRIVATE SECTION.
|
||||
|
||||
METHODS:
|
||||
space_leading_trailing FOR TESTING
|
||||
RAISING zcx_abapgit_exception.
|
||||
|
||||
METHODS:
|
||||
parse_xml
|
||||
IMPORTING
|
||||
iv_xml TYPE csequence
|
||||
RAISING
|
||||
zcx_abapgit_exception,
|
||||
render_xml
|
||||
IMPORTING
|
||||
iv_name TYPE string
|
||||
RETURNING
|
||||
VALUE(rv_xml) TYPE string.
|
||||
|
||||
DATA: mo_xml TYPE REF TO ltcl_xml_concrete.
|
||||
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
CLASS ltcl_xml IMPLEMENTATION.
|
||||
|
||||
METHOD parse_xml.
|
||||
|
||||
DATA: lv_xml TYPE string.
|
||||
|
||||
|
||||
CREATE OBJECT mo_xml.
|
||||
|
||||
lv_xml = |<?xml version="1.0"?>|
|
||||
&& |<{ mo_xml->c_abapgit_tag } { mo_xml->c_attr_version }="{ zif_abapgit_version=>gc_xml_version }">|
|
||||
&& iv_xml
|
||||
&& |</{ mo_xml->c_abapgit_tag }>|.
|
||||
|
||||
mo_xml->parse( iv_xml = lv_xml ).
|
||||
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD space_leading_trailing.
|
||||
|
||||
DATA: lv_from_xml TYPE string,
|
||||
lv_to_xml TYPE string.
|
||||
|
||||
|
||||
lv_from_xml = `<FOO> A </FOO>`.
|
||||
|
||||
parse_xml( lv_from_xml ).
|
||||
|
||||
lv_to_xml = render_xml( 'FOO' ).
|
||||
|
||||
cl_abap_unit_assert=>assert_equals(
|
||||
act = lv_to_xml
|
||||
exp = lv_from_xml ).
|
||||
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD render_xml.
|
||||
|
||||
DATA: li_element TYPE REF TO if_ixml_element,
|
||||
li_ostream TYPE REF TO if_ixml_ostream,
|
||||
li_renderer TYPE REF TO if_ixml_renderer,
|
||||
li_streamfactory TYPE REF TO if_ixml_stream_factory.
|
||||
|
||||
li_element = mo_xml->mi_xml_doc->find_from_path( |/{ mo_xml->c_abapgit_tag }/{ iv_name }| ).
|
||||
|
||||
li_streamfactory = mo_xml->mi_ixml->create_stream_factory( ).
|
||||
|
||||
li_ostream = li_streamfactory->create_ostream_cstring( rv_xml ).
|
||||
|
||||
li_element->render( ostream = li_ostream ).
|
||||
|
||||
ENDMETHOD.
|
||||
|
||||
ENDCLASS.
|
|
@ -10,6 +10,7 @@
|
|||
<CLSCCINCL>X</CLSCCINCL>
|
||||
<FIXPT>X</FIXPT>
|
||||
<UNICODE>X</UNICODE>
|
||||
<WITH_UNIT_TESTS>X</WITH_UNIT_TESTS>
|
||||
</VSEOCLASS>
|
||||
</asx:values>
|
||||
</asx:abap>
|
||||
|
|
Loading…
Reference in New Issue
Block a user