cancel
Showing results for 
Search instead for 
Did you mean: 

Carriage Return(enter) at the end of each tag of xml file

Former Member
0 Kudos

Hi Experts,

I have to downloading data from the browser in XML form.

I am using the below code. am using

" CONCATENATE V_XML '\R\N' INTO V_XML. " as a carriage return. As after every tag I need 'enter' in the output. How do we capture Carriage Return(enter) at the end of each tag of xml file

data : V_XML TYPE STRING.

data : v_xml1 type xstring.

CONCATENATE

V_XML '<TimeStamp>' wa_XML-TimeStamp '</TimeStamp>' INTO V_XML.

*APPEND V_XML TO IT_XML.

CONCATENATE

V_XML '\R\N' INTO V_XML.

CONCATENATE

V_XML '<SupportCaseID>' wa_XML-SupportCaseID '</SupportCaseID>' INTO V_XML.

*APPEND V_XML TO IT_XML.

CALL FUNCTION 'SCMS_STRING_TO_XSTRING'

EXPORTING

TEXT = V_XML

  • MIMETYPE = ' '

  • ENCODING =

IMPORTING

BUFFER = v_xml1

EXCEPTIONS

FAILED = 1

OTHERS = 2.

CALL METHOD CL_WD_RUNTIME_SERVICES=>ATTACH_FILE_TO_RESPONSE

EXPORTING

I_FILENAME = 'c:/temp/test.XML'

I_CONTENT = v_xml1

I_MIME_TYPE = 'XML'.

Regards,

Vishal.

FULL POINTS WOULD BE REWARDED.

Accepted Solutions (1)

Accepted Solutions (1)

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

I wouldn't use \R\N. You should be using CL_ABAP_CHAR_UTILITIES. There are static kernel constants for the major non-printable characters like newline and cr_lf.

Former Member
0 Kudos

Hi Thomas,

I am getting following error:

"

Only one top level element is allowed in an XML document. Error processing resource 'file:///C:/Users/guptavis/AppData/Loca...

<SupportCaseID>0055000018</SupportCaseID>

-^

"

for the below code

DATA: LV_NEWLINE TYPE ABAP_CR_LF.

LV_NEWLINE = CL_ABAP_CHAR_UTILITIES=>CR_LF.

CONCATENATE

V_XML '<TimeStamp>' wa_XML-TimeStamp '</TimeStamp>' INTO V_XML.

CONCATENATE

V_XML lv_newline INTO V_XML.

CONCATENATE

V_XML '<SupportCaseID>' wa_XML-SupportCaseID '</SupportCaseID>' INTO V_XML.

CALL FUNCTION 'SCMS_STRING_TO_XSTRING'

EXPORTING

TEXT = V_XML

  • MIMETYPE = ' '

  • ENCODING =

IMPORTING

BUFFER = V_XML1

EXCEPTIONS

FAILED = 1

OTHERS = 2.

CALL METHOD CL_WD_RUNTIME_SERVICES=>ATTACH_FILE_TO_RESPONSE

EXPORTING

I_FILENAME = 'C:/TEMP/TEST.XML'

I_CONTENT = V_XML1

I_MIME_TYPE = 'XML'.

Do you have anyu idea how can I rectify this error. As per my requirement I have conncatinate so many more lines.

Regards,

Vishal.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

I'm not sure how anyone can help you. You originally asked for Carriage Return - and that was provided. But this error message has to do with the structure of your XML document itself and how it is processed on the receiving end. I don't see how anyone can help you with that - without knowing the requirements of hte XML document you are trying to build. You are into your application specific requirements now.

Former Member
0 Kudos

Hi Thomas,

I am trying to generate the following structure.....

<?xml version="1.0" standalone="yes" ?>

<DataExchange>

<TimeStamp>1203200717230000</TimeStamp>

<SupportCaseID>Notification number</SupportCaseID>

<Caller>UserId SAP</Caller>

<Product>Printready</Product>

<OS>Operation system of product, e.g. Windows</OS>

<Company>Customer name</Company>

<Operator>Customer contact name (Purchase order number)</Operator>

<OEmail>Operator e-Mail address</OEmail>

<Ocountry>USA</Ocountry>

</DataExchange>

I have to copy this in "upload.xml" file.

for this I am using following method to generate the file.

CALL METHOD CL_WD_RUNTIME_SERVICES=>ATTACH_FILE_TO_RESPONSE

EXPORTING

I_FILENAME = 'C:/UPLOAD.XML'

I_CONTENT = V_XML1

I_MIME_TYPE = 'XML'.

Here the problem is :

I am not getting the tags in newline......

Regards,

Vishal.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

>I am not getting the tags in newline

I'm afraid that I don't understand what you are saying? From the error message it looks like your XML file is not properly formatting - as in you have more than one root element. What does that have to do with newlines? You realize that Carriage Returns and Newlines are not necessary in XML. They are only put there to make the XML more human readable, but should never be required for the parsing.

What does the XML string look like in the debugger before you send it the fronted. I'm betting that you don't have correct nesting of the XML.

Former Member
0 Kudos

there was problem in :

CONCATENATE

'<?xml version=' '"1.0"' 'standalone=' '"yes"' '?>' INTO V_XML.

I have changed it to :

CONCATENATE

'<?xml version=' '"1.0"' ' standalone=' '"yes"' ' ?>' INTO V_XML.

have put spaces before "?" and "standalone"

Regards,

vishal.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

>

> there was problem in :

>

> CONCATENATE

> '<?xml version=' '"1.0"' 'standalone=' '"yes"' '?>' INTO V_XML.

>

> I have changed it to :

>

> CONCATENATE

> '<?xml version=' '"1.0"' ' standalone=' '"yes"' ' ?>' INTO V_XML.

>

> have put spaces before "?" and "standalone"

>

>

> Regards,

> vishal.

As a side note - you can use string constants - the ` instead of ' to make concatenations with quotes easier:

Of course then for this one you don't even need a concatenate:

MOVE

`<?xml version="1.0" standalone="yes" ?>` TO V_XML.

Answers (1)

Answers (1)

Former Member
0 Kudos

Thanks Thomas. My code is working now.

Points rewarded.

Edited by: VISHAL GUPTA on Jul 1, 2008 11:36 AM