cancel
Showing results for 
Search instead for 
Did you mean: 

How to show an XML String in Web Dynpro?

Former Member
0 Kudos

Hey Guys,

i have an XML string and i want to show this one like in an Internet Explorer.

With colours and well-arranged.

At the moment i only have this textedit, but there it is totally unclear.

Or is there a possibility to open an IE out of the WebDynpro which shows the XML string?

Thank you for your help

Best Regards

Thalin

Accepted Solutions (1)

Accepted Solutions (1)

vineetrrakesh
Explorer
0 Kudos

Hi Thalin,

You may use cl_wd_runtime_services=>attach_file_to_response (you can use proper MIME type with this method for showing in HTML) to as the user for Open-Save-cancel. On click of Open it will show the XML as per the user default application setting, typically IE.

Hope this solvs your problem.

Regards

Vineet

Former Member
0 Kudos

Hey,

thanks for your replies.

I tried to display the xml content in an IFrame, but my problem is, that i only have an string.

So i tried to upload this string to the ICM Server-Clipboard and generate an URL which i can bind to the Iframe element.

But i can only see a white page.

Here is my coding.

Whats my mistake? =S


  DATA: 
        lo_nd_iframe      TYPE REF TO if_wd_context_node,
        lo_el_iframe      TYPE REF TO if_wd_context_element,
        lv_content        TYPE wd_this->element_transdat-content,
        lo_http_response  TYPE REF TO if_http_response,
        lv_url            TYPE string,
        lv_guid           TYPE guid_32.

CREATE OBJECT lo_http_response TYPE cl_http_response.

  lo_http_response->set_cdata( lv_content ).
  lo_http_response->set_content_type( 'text/html' ).
  lo_http_response->server_cache_expire_rel( expires_rel = 500 ).
  lo_http_response->set_status( code = 200 reason = 'OK' ).

  CALL FUNCTION 'GUID_CREATE'
    IMPORTING
      ev_guid_32 = lv_guid.

  CONCATENATE lv_guid '.' 'html' INTO lv_url.

  cl_http_server=>server_cache_upload(
    EXPORTING
      url      = lv_url
      response = lo_http_response ).


  lo_nd_iframe = wd_context->get_child_node( name = wd_this->wdctx_iframe ).

  lo_el_iframe = lo_nd_iframe->get_element( ).
  lo_el_iframe->set_attribute(
    name =  `URL`
    value = lv_url ).

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

You are on the right path by adding the content to the ICM cache. Your generated URL might not be correct. I always build it like the following:

concatenate '/sap/public/' lv_guid '.' 'html' into lv_url.

Former Member
0 Kudos

Ok, now i don't have a white page anymore.

But now there is a dump.

Service is not available.

Error code 404

Reason Not found

The generated url is:

http://.../sap/public/E02A274D07BC91F1A74D0015178F7C74.html

So what do i have to do now?

vineetrrakesh
Explorer
0 Kudos

Hi Thalin,

The ICF of your WEbdynpro needs to be activated through tcode SICF. It may be the case that you are using your application which is embedded in some other WD but the generated URL has you component's name in the URL for the Iframe.

Alternatively you can just try the method i have given you in my prvious reply, it is quite simple which i have used in my application to show the XML in default browser. I generate and display my XML on click of a button in my WD application.

Regards

Vineet

gill367
Active Contributor
0 Kudos

Check whether the public services nod eis activated.

it will be there in sap/public right click on this node and check whether it is activated.

and then you need to modify the code little bit to show it with xml tags.

otherwise only the content will be shown.

here is the code that i used.

just in place of html you need to give xml.

data: cached_response type ref to if_http_response.
  create object cached_response
    type
      cl_http_response
    exporting
      add_c_msg        = 1.
  data lv_html_text type string.
    DATA lo_el_context TYPE REF TO if_wd_context_element.
    DATA ls_context TYPE wd_this->element_context.
    DATA lv_content LIKE ls_context-content.
*   get element via lead selection
    lo_el_context = wd_context->get_element(  ).

*   get single attribute
    lo_el_context->get_attribute(
      EXPORTING
        name =  `CONTENT`
      IMPORTING
        value = lv_content ).




  lv_html_text = lv_content.
 data: l_app_type type string.

      cached_response->set_cdata( lv_html_text ).
      l_app_type = 'text/xml'.

 cached_response->set_header_field( name  = if_http_header_fields=>content_type
                                     value = l_app_type ).

  cached_response->set_status( code = 200 reason = 'OK' ).
  cached_response->server_cache_expire_rel( expires_rel = 60 ).
  data: guid type guid_32.
  call function 'GUID_CREATE'
    importing
      ev_guid_32 = guid.


  DATA lv_ulr LIKE ls_context-ulr.
   concatenate '/sap/public' '/' guid '.' 'xml' into lv_ulr.

  lo_el_context = wd_context->get_element(  ).

  cl_http_server=>server_cache_upload( url      = lv_ulr
                                       response = cached_response ).


  lo_el_context->set_attribute(

      name =  `ULR`
        value = lv_ulr ).

thanks

sarbjeet singh

Former Member
0 Kudos

Thanks sarbjeet singh, u solved my probleme.

The key was this:

create object cached_response

type

cl_http_response

exporting

add_c_msg = 1.

So it was possible to see a message and not a white page.

The Main problem was the xml string. It was not a correct format.

Thank you

Thalin

Answers (1)

Answers (1)

gill367
Active Contributor
0 Kudos

You can use iframe to display an HTML page.

[http://help.sap.com/saphelp_nw70ehp1/helpdata/en/15/c07941601b1d09e10000000a155106/content.htm|http://help.sap.com/saphelp_nw70ehp1/helpdata/en/15/c07941601b1d09e10000000a155106/content.htm]