‎2014 Mar 03 10:38 AM
i Need to fetch the XML file from the application server and place into internal table and i am getting error message while using the functional module SMUM_XML_PARSE and the error message is "line 1 col 1-unexpected symbol; expected '<', '</', entity reference, character data, CDATA section, processing instruction or comment" and could you please let me know how to resolve this issue?
TYPES: BEGIN OF T_XML,
raw(2000) TYPE C,
END OF T_XML.
DATA:GW_XML_TAB TYPE T_XML.
DATA: GI_XML_TAB TYPE TABLE OF T_XML INITIAL SIZE 0.
DATA:GI_STR TYPE STRING.
data: GV_XML_STRING TYPE XSTRING.
DATA: GI_XML_DATA TYPE TABLE OF SMUM_XMLTB INITIAL SIZE 0.
data:GI_RETURN TYPE STANDARD TABLE OF BAPIRET2.
OPEN DATASET LV_FILE1 FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF SY-SUBRC NE 0.
MESSAGE 'File does not exist' TYPE 'E'.
ELSE.
DO.
* Transfer the contents from the file to the work area of the internal table
READ DATASET LV_FILE1 INTO GW_XML_TAB.
IF SY-SUBRC EQ 0.
CONDENSE GW_XML_TAB.
* Append the contents of the work area to the internal table
APPEND GW_XML_TAB TO GI_XML_TAB.
ELSE.
EXIT.
ENDIF.
ENDDO.
ENDIF.
* Close the file after reading the data
CLOSE DATASET LV_FILE1.
IF NOT GI_XML_TAB IS INITIAL.
CONCATENATE LINES OF GI_XML_TAB INTO GI_STR SEPARATED BY SPACE.
ENDIF.
* The function module is used to convert string to xstring
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
TEXT = GI_STR
IMPORTING
BUFFER = GV_XML_STRING
EXCEPTIONS
FAILED = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE 'Error in the XML file' TYPE 'E'.
ENDIF.
ENDIF.
*
IF GV_SUBRC = 0.
* Convert XML to internal table
CALL FUNCTION 'SMUM_XML_PARSE'
EXPORTING
XML_INPUT = GV_XML_STRING
TABLES
XML_TABLE = GI_XML_DATA
RETURN = GI_RETURN.
ENDIF.
READ TABLE GI_RETURN TRANSPORTING NO FIELDS WITH KEY TYPE = 'E'.
IF SY-SUBRC EQ 0.
MESSAGE 'Error converting the input XML file' TYPE 'E'.
ELSE.
DELETE GI_XML_DATA WHERE TYPE <> 'V'.
REFRESH GI_RETURN.
ENDIF.
‎2014 Mar 03 11:36 AM
Hi,
This one is working just fine.
Regards.
I am on windows network using unc file name \\folder\file.xml
PARAMETERS: p_file_i TYPE pathextern MODIF ID gr2 .
FORM get_data_1 .
IF p_file_i IS INITIAL .
MESSAGE e668(vl).
ENDIF .
DATA: mess TYPE string .
OPEN DATASET p_file_i FOR INPUT IN LEGACY BINARY MODE MESSAGE mess.
DATA: response_string_1 TYPE string .
DATA: response_string_2 TYPE xstring .
READ DATASET p_file_i INTO response_string_1 .
CALL METHOD cl_bcs_convert=>string_to_xstring
EXPORTING
iv_string = response_string_1
RECEIVING
ev_xstring = response_string_2.
DATA: it_xml_table TYPE TABLE OF smum_xmltb .
DATA: it_bapiret TYPE bapirettab .
CALL FUNCTION 'SMUM_XML_PARSE'
EXPORTING
xml_input = response_string_2
TABLES
xml_table = it_xml_table
return = it_bapiret.
BREAK-POINT .
* Check it_xml_table , it_bapiret
ENDFORM . "get_data_1
*----------------------------------------------------------------------*
‎2014 Mar 03 12:04 PM
still i am getting the same error i.e
"line 1 col 1-unexpected symbol; expected '<', '</', entity reference, character data, CDATA section, processing instruction or comment"
Actually the requirment is that the XML file is in application server and it is uploaded from the presenation server to application server using the tcode /nCG3Z
And from the application server i need to upload into the internal table
‎2014 Mar 03 12:13 PM
Hi,
Can you up load your XML file so I can test it here ?
Regards.
‎2014 Mar 03 12:17 PM
how i can upload file in SCN and could you please tell me or can u give me your email id and i will send the file to you or please send me your emailid to <Removed by Moderator> and i will send the file to you.
Message was edited by: Marcelo Ramos:
If you want people to contact you, you can choose to make your email visible in your profile, but we ask you not to post it elsewhere on the site.
Please check the The SCN Rules of Engagement for more information.
‎2014 Mar 03 12:28 PM
‎2014 Mar 03 12:32 PM
‎2014 Mar 03 12:33 PM
Hi,
Or post it as a message.
it is a text file after all...
Regards.
‎2014 Mar 03 12:32 PM
‎2014 Mar 03 12:35 PM
‎2014 Mar 03 1:00 PM
Debug:
Hi,
It seems that the xml is not well formed .
I remove some parts and then it works just fine.
It is showing in the browser as well.
Regards.
‎2014 Mar 03 1:21 PM
thanks for the help and i am able to upload it and could you please let me know what you had removed the some part in the XML file
‎2014 Mar 03 1:30 PM
You can learn how to do file comparison using any tool (Notepad++ for example).
One comparing 2 files, it can be seen that first 8 lines were removed, till <Soap:Body>.. And <?xml ..?> line was added in beginning.
‎2014 Mar 03 1:34 PM
Hi,
Thanks !!!
You are my time saver !!!!! (And more then once...)
Regards.
‎2014 Mar 03 1:41 PM
One more thing. If you don't want to install software just to compare text, you can do it via online text comparison website. One such website is DiffNow
‎2014 Mar 03 2:51 PM
Could you please tel me why the first 8 lines were removed, till <Soap:Body and also added the line <?xml version="1.0" encoding="UTF-8"?> in the beggining .
Becuase there will be lot of XML files will be coming from the Vendor daily and that should be uploaded in the application server and should update in the SAP tables based on the data in the XML file.
what information i need to give to vendor that do not add the first 8 lines in the XML file and add the line in the beggining <?xml version="1.0" encoding="UTF-8"?> ??????
Is there any other way we can do with out removing the lines?
‎2014 Mar 03 3:51 PM
Hi,
Ask the vendor to create a well formed file.
I do not know how he generate those but if he is doing it by "hand" this problen can occours.
If the vendor is using SAP he can use cl_ixml to generate the file for you.
Example: http://scn.sap.com/servlet/JiveServlet/download/38-233479/Y_R_EITAN_TEST_40_02.txt.zip
See http://scn.sap.com/community/abap/blog/2013/12/15/creating-excel-the-java-way
Regards.
‎2014 Mar 03 4:07 PM
You should try to understand the XML structure.
It starts with header, and then every opening tag has matching ending tag at same hierarchy level.
Deleting lines to make it work was one option. Another option is to add missing ending tags.
After adding the ending tags, it is opening in internet explorer even without the <?xml header.
See this attachment.