Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

XML Parsning

Former Member
0 Likes
721

Hello Experts,

I need to read xml file through ABAP, I have done all steps but still the returned object is empty. here is what I did:

XML:

<?xml version="1.0" encoding="ISO-8859-1"?>

<configuration>

<common>

<in_out_path>C:/SAP/CC1/IN-OUT</in_out_path>

<error_log_path>C:/SAP/CC1/ERROR-LOG</error_log_path>

<hr_mm_data_path>C:/SAP/CC1/mmdata</hr_mm_data_path>

</common>

</configuration>

ABAP Object:

TYPES: BEGIN OF tp_common,

in_out_folder(50) TYPE c,

error_log_folder(50) TYPE c,

hr_mm_data_folder(50) TYPE c,

END OF tp_common.

TYPES: BEGIN OF tp_config,

common TYPE tp_common,

END OF tp_config.

DATA: t_config TYPE STANDARD TABLE OF tp_config,

o_config TYPE tp_config.

DATA: gt_result_xml TYPE abap_trans_resbind_tab,

gs_result_xml TYPE abap_trans_resbind.

ABAP call

GET REFERENCE OF t_config INTO gs_result_xml-value.

gs_result_xml-name = 'OUT'.

APPEND gs_result_xml TO gt_result_xml.

TRY.

CALL TRANSFORMATION z_xml_to_abap

SOURCE XML xml_content

RESULT (gt_result_xml).

CATCH cx_root INTO gs_rif_ex.

gs_var_text = gs_rif_ex->get_text( ).

WRITE:/ 'Transformation error: ', gs_var_text.

EXIT.

ENDTRY.

Print Data:

LOOP AT t_config INTO o_config.

WRITE: / 'in_out_folder:', o_config-common-in_out_folder.

WRITE: / 'error_log_folder:', o_config-common-error_log_folder.

WRITE: / 'hr_mm_data_folder:', o_config-common-hr_mm_data_folder.

ENDLOOP.

XSTL:

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sap="http://www.sap.com/sapxsl" version="1.0">

<xsl:template match="/configuration">

<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">

<asx:values>

<OUT>

<xsl:variable name="comm" select="common" />

<common>

<in_out_folder><xsl:value-of select="$comm/in_out_path"/></in_out_folder>

<error_log_folder><xsl:value-of select="$comm/error_log_path" /></error_log_folder>

<hr_mm_data_folder><xsl:value-of select="$comm/hr_mm_data_path" /></hr_mm_data_folder>

</common>

</OUT>

</asx:values>

</asx:abap>

</xsl:template>

</xsl:transform>

Result on screen:

in_out_folder:

error_log_folder:

hr_mm_data_folder:

can you please help me urgently????? what is missing, no error is display but no data is there!!!! help pleaseeeee

Thanks in advance

6 REPLIES 6
Read only

Former Member
0 Likes
673

Hi Samir

Have you written ( CALL TRANSFORMATION z_xml_to_abap ) z_xml_to_abap program which one you used in CALL TRANSFORMATION.Kindly check the same.

Thanks

Gowrishanakr

Read only

0 Likes
673

Hello Experts,

I need to read xml file through ABAP, I have done all steps but still the returned object is empty. here is what I did:

XML:

<?xml version="1.0" encoding="ISO-8859-1"?>

<configuration>

<common>

<in_out_path>C:/SAP/CC1/IN-OUT</in_out_path>

<error_log_path>C:/SAP/CC1/ERROR-LOG</error_log_path>

<hr_mm_data_path>C:/SAP/CC1/mmdata</hr_mm_data_path>

</common>

</configuration>

ABAP Object:

TYPES: BEGIN OF tp_common,

in_out_folder(50) TYPE c,

error_log_folder(50) TYPE c,

hr_mm_data_folder(50) TYPE c,

END OF tp_common.

TYPES: BEGIN OF tp_config,

common TYPE tp_common,

END OF tp_config.

DATA: t_config TYPE STANDARD TABLE OF tp_config,

o_config TYPE tp_config.

DATA: gt_result_xml TYPE abap_trans_resbind_tab,

gs_result_xml TYPE abap_trans_resbind.

ABAP call

GET REFERENCE OF t_config INTO gs_result_xml-value.

gs_result_xml-name = 'OUT'.

APPEND gs_result_xml TO gt_result_xml.

TRY.

CALL TRANSFORMATION z_xml_to_abap

SOURCE XML xml_content

RESULT (gt_result_xml).

CATCH cx_root INTO gs_rif_ex.

gs_var_text = gs_rif_ex->get_text( ).

WRITE:/ 'Transformation error: ', gs_var_text.

EXIT.

ENDTRY.

Print Data:

LOOP AT t_config INTO o_config.

WRITE: / 'in_out_folder:', o_config-common-in_out_folder.

WRITE: / 'error_log_folder:', o_config-common-error_log_folder.

WRITE: / 'hr_mm_data_folder:', o_config-common-hr_mm_data_folder.

ENDLOOP.

XSLT:

<x sl:template match="/configuration">

<a sx: abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">

<a sx:values>

<OUT>

<x sl:variable name="comm" select="common" />

<common>

<in_out_folder><xsl:value-of select="$comm/in_out_path"/></in_out_folder>

<error_log_folder><xsl:value-of select="$comm/error_log_path" /></error_log_folder>

<hr_mm_data_folder><xsl:value-of select="$comm/hr_mm_data_path" /></hr_mm_data_folder>

</common>

</OUT>

</a sx:values>

</a sx:abap>

</x sl:template>

</x sl:transform>

Result on screen:

in_out_folder:

error_log_folder:

hr_mm_data_folder:

can you please help me urgently????? what is missing, no error is display but no data is there!!!! help pleaseeeee

Thanks in advance

Read only

0 Likes
673

Sorry, when I pasted the xslt part, the whole paragraph was messed up, so I pasted again the 1st message and gave all details. Thanks

Read only

0 Likes
673

Any feedback please!!!

Read only

0 Likes
673

Solved by using IXML instead. thanks

Read only

0 Likes
673

I am stuck at a similar issue. Could you kindly let me know how did you resolve the issue? Please provide source code if possible...

Regards

Balaji