"! <p class="shorttext synchronized" lang="en">XML to JSON Conversion</p>
CLASS ZCL_XML_TO_JSON DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .

  PUBLIC SECTION.
    INTERFACES IF_OO_ADT_CLASSRUN.
  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.



CLASS ZCL_XML_TO_JSON IMPLEMENTATION.


  METHOD IF_OO_ADT_CLASSRUN~MAIN.
    DATA(XML) = CL_ABAP_CONV_CODEPAGE=>CREATE_OUT(  )->CONVERT(
       `<object><str name="TEXT">JSON</str></object>` ).
    DATA(XML_READER) = CL_SXML_STRING_READER=>CREATE( XML ).
    DATA(JSON_WRITER) = CL_SXML_STRING_WRITER=>CREATE( TYPE = IF_SXML=>CO_XT_JSON ).
    XML_READER->NEXT_NODE( ).
    XML_READER->SKIP_NODE(  JSON_WRITER ).

    TRY.
        DATA(READER) = CL_SXML_STRING_READER=>CREATE( JSON_WRITER->GET_OUTPUT(  ) ).
        DATA(WRITER) = CAST IF_SXML_WRITER(
                              CL_SXML_STRING_WRITER=>CREATE( TYPE = IF_SXML=>CO_XT_JSON ) ).
        WRITER->SET_OPTION( OPTION = IF_SXML_WRITER=>CO_OPT_LINEBREAKS ).
        WRITER->SET_OPTION( OPTION = IF_SXML_WRITER=>CO_OPT_INDENT ).
        READER->NEXT_NODE( ).
        READER->SKIP_NODE( WRITER ).
        DATA(JSON_OUTPUT) = CL_ABAP_CONV_CODEPAGE=>CREATE_IN(  )->CONVERT( CAST CL_SXML_STRING_WRITER( WRITER )->GET_OUTPUT( ) ).

      CATCH CX_SXML_PARSE_ERROR.
        RETURN.
    ENDTRY.
    OUT->WRITE( JSON_OUTPUT ).

  ENDMETHOD.
ENDCLASS.
