on ‎2016 Mar 08 11:51 AM
Hi Friends,
I have a requirement to get the XSTRING (Data Element: XSTRINGVAL[ Data Type: RAWSTRING ]) from data base table and convert to XML STRING. Please let me know if there is any demo programs.
I googled could not find the right one.
Thanks a lot for your help.
Kind Regards,
Madhu M V
Request clarification before answering.
Hi,
I am not sure that this is what you need but some code:
*----------------------------------------------------------------------*
FORM test_02
USING
xml_string TYPE xstring .
DATA: ob_ixml TYPE REF TO if_ixml. " Interface of Factory Object
ob_ixml = cl_ixml=>create( ).
DATA: ob_ixml_streamfactory TYPE REF TO if_ixml_stream_factory. " Factory for Streams
ob_ixml_streamfactory = ob_ixml->create_stream_factory( ).
DATA: ob_ixml_istream TYPE REF TO if_ixml_istream. " Input Streams
ob_ixml_istream = ob_ixml_streamfactory->create_istream_xstring( string = xml_string ).
DATA: ob_ixml_document TYPE REF TO if_ixml_document. " XML Document in DOM Representation
ob_ixml_document = ob_ixml->create_document( ) .
DATA: ob_parser TYPE REF TO if_ixml_parser. " Parser
ob_parser = ob_ixml->create_parser( stream_factory = ob_ixml_streamfactory
istream = ob_ixml_istream
document = ob_ixml_document ).
ob_parser->parse( ).
DATA: ob_ixml_stream_factory TYPE REF TO if_ixml_stream_factory. " Factory for Streams
DATA: ob_ixml_ostream TYPE REF TO if_ixml_ostream . " Output Streams
* If you need xstring output
* DATA: xstring TYPE xstring.
* ob_ixml_stream_factory = ob_ixml->create_stream_factory( ).
* ob_ostream = ob_ixml_stream_factory->create_ostream_xstring( xstring ).
* ob_ostream->set_pretty_print( abap_true ).
* ob_ixml_document->render( ostream = ob_ostream ) .
DATA: debug TYPE string.
* For debug purpose only
ob_ixml_stream_factory = ob_ixml->create_stream_factory( ).
ob_ixml_ostream = ob_ixml_stream_factory->create_ostream_cstring( debug ).
ob_ixml_ostream->set_pretty_print( abap_true ).
ob_ixml_document->render( ostream = ob_ixml_ostream ) .
* At this point we have XML
* Look at variable debug using the XML view .
BREAK-POINT .
ENDFORM.
*----------------------------------------------------------------------*
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Eitan,
Thanks for giving me reference. I formatted and not able to understand in WHICH variable we get XML string or XML content.
Please guide.
Thanks a lot for your help.
Thanks,
Madhu M V
REPORT z.
DATA: ob_ixml TYPE REF TO if_ixml,
ob_ixml_streamfactory TYPE REF TO if_ixml_stream_factory,
lv_xsrting TYPE xstringval,
ob_ixml_istream TYPE REF TO if_ixml_istream,
ob_ixml_document TYPE REF TO if_ixml_document,
ob_parser TYPE REF TO if_ixml_parser,
ob_ixml_stream_factory TYPE REF TO if_ixml_stream_factory,
ob_ixml_ostream TYPE REF TO if_ixml_ostream,
debug TYPE string.
*&-Get My XSTRING value for XML file uploaded previously-&*
SELECT SINGLE xstring FROM zf4m_template INTO lv_xsrting.
ob_ixml = cl_ixml=>create( ).
ob_ixml_streamfactory = ob_ixml->create_stream_factory( ).
ob_ixml_istream = ob_ixml_streamfactory->create_istream_xstring( string = lv_xsrting ).
ob_ixml_document = ob_ixml->create_document( ) .
ob_parser = ob_ixml->create_parser( stream_factory = ob_ixml_streamfactory
istream = ob_ixml_istream
document = ob_ixml_document ).
ob_parser->parse( ).
* For debug purpose only
ob_ixml_stream_factory = ob_ixml->create_stream_factory( ).
ob_ixml_ostream = ob_ixml_stream_factory->create_ostream_cstring( debug ).
ob_ixml_ostream->set_pretty_print( abap_true ).
ob_ixml_document->render( ostream = ob_ixml_ostream ) .
WRITE: / 'test'.
Hi,
In variable "debug" you see the string representation of ob_ixml_document .
Can you tell us the big picture ? what are you trying to archive ?
imho you need to do some reading:
http://help.sap.com/abapdocu_740/en/abenabap_ixml_lib.htm
Regards..
My requirement: I have XML data (PDF FILE converted to XML) in XSTRING format in SAP database table. I need to read this XSTRING and convert back to XML string and give it back as export parameter in function module.
Data: lv_xsrting TYPE xstringval
*&-Get My XSTRING value for XML file uploaded previously-&*
SELECT SINGLE xstring FROM zf4m_template INTO lv_xsrting.
So I need a fuction module or a method which takes xstring and give me XML back. So that I can send it through export parameter of calling function module.
Hope this is clear now.
Sorry for the confusion.
thanks,
Madhu M V
https://scn.sap.com/thread/1566979
Hi Madhu,
I think xstring and xmlstring both are same. What I understand from your requirement is converting xstring to xml file. you are reading xstring from database and trying to convert to xml file. Please follow the above link if it helps you. Try achieving this with call transformation instead of FM.
Thanks
Rashmi
Hi,
I am more confuse now "PDF FILE converted to XML" is not clear to me unless you have a situation like this:
http://scn.sap.com/servlet/JiveServlet/downloadImage/2-16506971-881200/pastedImage_0.png
Do you know what the people put in zf4m_template (I mean the original file) ?
If you have xstring and you want to convert it string please try this code:
FORM xstring2string
USING
xstring TYPE xstring
CHANGING
string TYPE string .
DATA: ob_abap_conv_in_ce TYPE REF TO cl_abap_conv_in_ce .
TRY.
CALL METHOD cl_abap_conv_in_ce=>create
EXPORTING
input = xstring
replacement = '?'
ignore_cerr = abap_true
RECEIVING
conv = ob_abap_conv_in_ce.
CATCH cx_parameter_invalid_range .
CATCH cx_sy_codepage_converter_init .
ENDTRY.
TRY.
CALL METHOD ob_abap_conv_in_ce->read
IMPORTING
data = string.
CATCH cx_sy_conversion_codepage .
CATCH cx_sy_codepage_converter_init .
CATCH cx_parameter_invalid_type .
CATCH cx_parameter_invalid_range .
ENDTRY.
ENDFORM . "Xstring2String
Regards.
Thanks Eitan, your input help me:
here is what I did:
DATA : BEGIN OF ls_binary,
binary_field(1000) TYPE c,
END OF ls_binary.
Data: ls_xstring TYPE xstring,
lv_size TYPE i,
lt_binary_tab LIKE TABLE OF ls_binary,
lv_xml_string TYPE string,
CALL METHOD cl_abap_zip->get
EXPORTING
name = ls_zipped_files-name
IMPORTING
content = ls_xstring
EXCEPTIONS
zip_index_error = 1
zip_decompression_error = 2
OTHERS = 3.
*&-Convert Xstring to Binary-&*
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = ls_xstring
IMPORTING
output_length = lv_size
TABLES
binary_tab = lt_binary_tab.
*&-Convert Binary to string-&*
*Convert uploaded data to string
CALL FUNCTION 'SCMS_BINARY_TO_STRING'
EXPORTING
input_length = lv_size
IMPORTING
text_buffer = lv_xml_string
TABLES
binary_tab = lt_binary_tab
EXCEPTIONS
failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
In lv_xml_string i have my XML.
Thanks a lot for your help.
Appreciate.
Madhu M V
| User | Count |
|---|---|
| 7 | |
| 6 | |
| 5 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.