‎2007 Aug 30 4:50 PM
I created an XSLT transformation called "ZSIMPLEXSLT" and wrote the following code to try and transform some data on a web server. When the code gets to the CALL TRANSFORMATION line it bombs saying that I've tried to invoke a method on an object reference that's null. It's talking about <b>istream</b> because in the Globals list I can see this dataobject is still INITIAL. Does anybody know why the call to create_istream_uri( ) is failing to return an istream?
TYPE-POOLS: abap.
TYPE-POOLS: ixml.
CLASS cl_ixml DEFINITION LOAD.
DATA g_ixml TYPE REF TO if_ixml.
DATA streamfactory TYPE REF TO if_ixml_stream_factory.
DATA istream TYPE REF TO if_ixml_istream.
DATA xmlstr TYPE string.
DATA ex TYPE REF TO CX_SY_REF_IS_INITIAL.
DATA imsg TYPE REF TO IF_MESSAGE.
DATA smsg TYPE string.
START-OF-SELECTION.
g_ixml = cl_ixml=>create( ).
streamfactory = g_ixml->create_stream_factory( ).
istream = streamfactory->create_istream_uri( 'http://www.somewhere.com/data.xml' ).
TRY.
CALL TRANSFORMATION zsimplexslt
SOURCE XML istream
RESULT XML xmlstr.
CATCH CX_SY_REF_IS_INITIAL INTO ex.
imsg = ex.
WRITE / 'EXCEPTION THROWN:'.
smsg = imsg->GET_LONGTEXT( ).
smsg = imsg->GET_TEXT( ).
WRITE / smsg.
ENDTRY.
‎2007 Oct 03 11:07 PM
Hello Steve
I am not sure whether method
streamfactory->create_istream_uri
is able to make a HTTP connection to a web site. All the sample reports in package SIXML_TEST (ECC 5.0) deal with files located either on the local PC or the application server.ZUS_SDN_SIMPLE_XSLT
is a mélange of your coding and pieces out of report RSHTTP02 (HTTP client test, package SHTTP).*&---------------------------------------------------------------------*
*& Report ZUS_SDN_SIMPLE_XSLT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zus_sdn_simple_xslt.
TYPE-POOLS: abap.
TYPE-POOLS: ixml.
CLASS cl_ixml DEFINITION LOAD.
DATA g_ixml TYPE REF TO if_ixml.
DATA streamfactory TYPE REF TO if_ixml_stream_factory.
DATA istream TYPE REF TO if_ixml_istream.
DATA xmlstr TYPE string.
DATA x_string TYPE xstring.
DATA ex TYPE REF TO cx_sy_ref_is_initial.
DATA imsg TYPE REF TO if_message.
DATA smsg TYPE string.
DATA:
go_client TYPE REF TO if_http_client.
START-OF-SELECTION.
g_ixml = cl_ixml=>create( ).
streamfactory = g_ixml->create_stream_factory( ).
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = 'http://www.w3schools.com/xsl/cdcatalog.xml'
* PROXY_HOST =
* PROXY_SERVICE =
* SSL_ID =
* SAP_USERNAME =
* SAP_CLIENT =
IMPORTING
client = go_client
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
go_client->request->set_method( 'GET' ).
go_client->request->set_version(
if_http_request=>co_protocol_version_1_0 ).
cl_http_utility=>set_request_uri( request = go_client->request
uri = 'GET' ).
CALL METHOD go_client->send( ).
CALL METHOD go_client->receive( ).
x_string = go_client->response->if_http_entity~get_data( ).
istream = streamfactory->create_istream_xstring( x_string ).
** CALL METHOD streamfactory->create_istream_uri
** EXPORTING
*** public_id = 'http://www.w3schools.com/xsl/cdcatalog.xml'
** system_id = 'http://www.w3schools.com/xsl/cdcatalog.xml'
** RECEIVING
** rval = istream.
CHECK ( istream IS BOUND ).
** istream = streamfactory->create_istream_uri(
** 'http://www.w3schools.com/xsl/cdcatalog.xml' ).
TRY.
CALL TRANSFORMATION zsimplexslt
SOURCE XML istream
RESULT XML xmlstr.
CATCH cx_sy_ref_is_initial INTO ex.
imsg = ex.
WRITE / 'EXCEPTION THROWN:'.
smsg = imsg->get_longtext( ).
smsg = imsg->get_text( ).
WRITE / smsg.
ENDTRY.Regards
Uwe
PS: Please forgive that I have renamed your report but it makes tracking of "my" sample reports in the SDN easier...
‎2007 Oct 04 6:56 AM
Hi
<b>XSLT Program</b>
Named as "YCOMPLEX_XML_TO_ABAP"
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sap="http://www.sap.com/abapxml" version="1.0">
<xsl:template match="//I_DATA">
<asx:abap xmlns:asx="http://www.sap.com/abapxml">
<asx:values>
<I_DATA>
<xsl:for-each select="DETAIL">
<I_DATA1>
<KEY1>
<xsl:value-of select="KEY1"/>
</KEY1>
<KEY2>
<xsl:value-of select="KEY2"/>
</KEY2>
<CONT>
<xsl:for-each select="CONT">
<CONT1>
<CONTENT1>
<xsl:value-of select="CONTENT1"/>
</CONTENT1>
<CONTENT2>
<xsl:value-of select="CONTENT2"/>
</CONTENT2>
</CONT1>
</xsl:for-each>
</CONT>
</I_DATA1>
</xsl:for-each>
</I_DATA>
</asx:values>
</asx:abap>
</xsl:template>
</xsl:transform>
ABAP Program to test the transformation
REPORT y_test_xml_tran.
TYPES: BEGIN OF con ,
content1(20),
content2(20),
END OF con .
TYPES: contype TYPE con OCCURS 0.
TYPES: BEGIN OF i_det,
key1(10),
key2(10),
cont TYPE contype ,
END OF i_det.
DATA: i_data TYPE TABLE OF i_det.
DATA: xml_string TYPE string .
DATA: xslt_error TYPE REF TO cx_xslt_exception,
xslt_message TYPE string .
CLEAR xml_string .
CONCATENATE
`<?xml version="1.0" encoding="utf-8"?>`
`<asx:abap xmlns:asx="http://www.sap.com/abapxml">`
`<asx:values>`
`<I_DATA>`
`<DETAIL>`
`<KEY1>John</KEY1>`
`<KEY2>Smith</KEY2>`
`<CONT>`
`<CONTENT1>RICK ROAD</CONTENT1>`
`<CONTENT2>Japan</CONTENT2>`
`</CONT>`
`<CONT>`
`<CONTENT1>RICK ROAD1</CONTENT1>`
`<CONTENT2>Japan1</CONTENT2>`
`</CONT>`
`<CONT>`
`<CONTENT1>RICK ROAD2</CONTENT1>`
`<CONTENT2>Japan2</CONTENT2>`
`</CONT>`
`</DETAIL>`
`<DETAIL>`
`<KEY1>Micheal</KEY1>`
`<KEY2>June</KEY2>`
`<CONT>`
`<CONTENT1>PAN ROAD</CONTENT1>`
`<CONTENT2>England</CONTENT2>`
`</CONT>`
`<CONT>`
`<CONTENT1>PAN ROAD1</CONTENT1>`
`<CONTENT2>England1</CONTENT2>`
`</CONT>`
`</DETAIL>`
`</I_DATA>`
`</asx:values>`
`</asx:abap>`
INTO xml_string .
TRY .
CALL TRANSFORMATION (`YCOMPLEX_XML_TO_ABAP`)
SOURCE XML xml_string
RESULT i_data = i_data.
CATCH cx_xslt_exception INTO xslt_error.
xslt_message = xslt_error->get_text( ).
ENDTRY.http://help.sap.com/saphelp_nw2004s/helpdata/en/a8/824c3c66177414e10000000a114084/frameset.htm
Hope this helps.
<b>Reward i fuseful</b>