on 04-08-2011 8:03 AM
Hi All,
Could anyone tell how xml string can be bound to context nodes ? In my requirement i need to serialize context nodes value to string and deserialize it back to nodes for implementing back naviagtion between views.
I didnt see much threads achieving this giving details on class cl_wdr_xml_convert_util and methods if_wd_client_conversion_util~string_to_struct.
I am using wd_context->to_xml to convert into xml.
From this format, i want to bind it back to context node.
When i use this below approch i get short dumb.
Serialization to xml:
lv_data_string = wd_context->to_xml( ).
Deserialization:
DATA lv_typedescr TYPE REF TO cl_abap_typedescr.
FIELD-SYMBOLS:
<fs_data> TYPE ANY TABLE.
CALL METHOD cl_abap_typedescr=>describe_by_object_ref
EXPORTING
p_object_ref = wd_context
RECEIVING
p_descr_ref = lv_typedescr
EXCEPTIONS
reference_is_initial = 1
OTHERS = 2.
try.
CALL METHOD cl_wdr_xml_convert_util=>if_wd_client_conversion_util~string_to_struct
EXPORTING
in = lv_data_string
typedescr = lv_typedescr
IMPORTING
data = <fs_data>
.
CATCH cx_wdr_conversion_exception into lo_err .
lv_exp = lo_err->get_text( ).
ENDTRY.
wd_context->bind_table( values = <fs-data>.
Using this way, i get a short dumb as assert statement is failed as value for typedescr->type_kind is '*'.
method if_wd_client_conversion_util~string_to_struct.
assert typedescr->type_kind = cl_abap_typedescr=>typekind_struct1
or typedescr->type_kind = cl_abap_typedescr=>typekind_struct2.
raise exception type cx_wdr_conversion_exception
exporting textid = cx_wdr_conversion_exception=>illegal_type.
On debugging changing this value to required also made no difference, as no value could be assigned to the field symbol.
Suggest a soution to do this.
>Using this way, i get a short dumb as assert statement is failed as value for typedescr->type_kind is '*'.
The problem is you are building an RTTI of an object reference. This isn't what this method needs.
CALL METHOD cl_wdr_xml_convert_util=>if_wd_client_conversion_util~string_to_struct
This method converts an XML string back into a ABAP data structure. It needs an RTTI of the structure not the WD_CONTEXT object.
So instead of this:
CALL METHOD cl_abap_typedescr=>describe_by_object_ref
EXPORTING
p_object_ref = wd_context
You need need to create a type descriptor object for the actual structure bound to the context node.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
HI Thomas,
Thanks for your response.
Could you sample the code on what i should do.
Based on your changes, i have changed the following below:
CALL METHOD cl_abap_typedescr=>describe_by_data ( before it was describe_by_object_ref)
EXPORTING
p_data = lo_nd_bp
receiving
p_descr_ref = lv_typedescr
CALL METHOD cl_wdr_xml_convert_util=>if_wd_client_conversion_util~string_to_struct
EXPORTING
in = lv_data_string
typedescr = lv_typedescr
IMPORTING
data = go_ref "<fs_data>
.
CATCH cx_wdr_conversion_exception into lo_err .
lv_exp = lo_err->get_text( ).
ENDTRY.
assign go_ref->* to <fs_data>.
wd_context->bind_table(
new_items = <fs_data>
set_initial_elements = abap_true
).
I stll get the dumb.
Thank you for the inputs.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You switched to describe_by_data, but you aren't giving it a data object. You are giving it the object reference to your node. You need to give the typedescr class a data object that matches the structure you used to define your node. Your coding is right by the object you are passing into the method isn't.
Hi Thomas,
Thanks for your replies.
I have corrected it, but the field symbol is empty and while debugging it says data type is incorrect.
code:
FIELD-SYMBOLS:
<fs_data> TYPE ANY TABLE.
data: lsbp type ZXBPCENTRAL,
go_ref type ref to data.
CALL METHOD cl_abap_typedescr=>describe_by_data " ( before it was describe_by_object_ref)
EXPORTING
p_data = lsbp
receiving
p_descr_ref = lv_typedescr.
try.
CALL METHOD cl_wdr_xml_convert_util=>if_wd_client_conversion_util~string_to_struct
EXPORTING
in = lv_data_string
typedescr = lv_typedescr
IMPORTING
data = go_ref "<fs_data>
.
CATCH cx_wdr_conversion_exception into lo_err .
lv_exp = lo_err->get_text( ).------> Here the error says " Invalid data type and hence, there is no data.
ENDTRY.
assign go_ref->* to <fs_data>.
I am still looking for solution and thanks a lot ....
>
> hi Thomas,
>
> Indeed i am really confused what to do.
> could you please sample a code for me? It will be a great help from u.
>
> thanks..
Your code is basically correct. You just need to fill the data reference before calling the string_to_struct method.
Something like:
get reference of lsbp into go_ref.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.