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 escaping issue in ABAP during XML file transfer to App. Server.

Former Member
0 Likes
4,375

Hello Partners:

I was going through some work of XML integration of SAP with a third-party. But came across an issue:

The text descriptions we are sending within an XML tag has certain special characters like '&'. But the XML parser is not escaping it. Hence its replacing '&' with "&" in the XML data string. So now I need to understand how can we implement escaping via ABAP for generated XML strings? Can you all please help me to understand which methods to use and how?

It will be much appreciated.

Thanks in advance.

Vivek Singh.

Hello Partners:

I was going through some work of XML integration of SAP with a third-party. But came across an issue:

The text descriptions we are sending within an XML tag has certain special characters like '&'. But the XML parser is not escaping it. Hence its replacing '&' with "&" in the XML data string. So now I need to understand how can we implement escaping via ABAP for generated XML strings? Can you all please help me to understand which methods to use and how?

It will be much appreciated.

Thanks in advance.

Vivek Singh.

12 REPLIES 12
Read only

Former Member
0 Likes
3,222

Hi,

It got escaped in this message I posted!

The issue is "&" being replaced by "& a m p ;". Please ignore the spaces in the latter, I have put it purposely to avoid the 'amp;' from being escaped when the browser parses this message.

Thanks.

Read only

0 Likes
3,222

cl_http_utility->IF_HTTP_UTILITY~ESCAPE_HTML will escape those special characters.

Read only

0 Likes
3,222

Thanks Raja. Will try this as well. However I managed to understand one thing that I need to pass the "XML line breaks" ie. something like "& # x a; & # x b;" within the tags to actually see texts in a new line on browser.

What you have provided may be correct but appears to be HTML line breaks ie. <br> tag. Let me re-try and I will let you know.

Thanks.

Read only

0 Likes
3,222

Hi Raja,

Cl_http_utility->IF_HTTP_UTILITY~ESCAPE_HTML did not solve my problem. Probably what I need is to avoid escaping i.e. unescape. Since, then the "& # x d ;" would remain the same rather than changing to "& a m p ; # x d ;".

Do you know of anyway to unescape values in XML? There's something like

l_ostream->set_ignore_escaping( ignore_escaping = ' ' ), but I don't know how to use this. Could you be able to help?

Thanks in advance for your efforts.

Best Regards.

Read only

0 Likes
3,222

within xml document, element text cannot have &, you have to encode it and and use it. while displaying it (as xml) in the browser also, it will show it as "& a m p ; "

in your application, if you want it just as &, the you have to unescape it .

i am searching for hwo this can (unescape) in abap. i will update the thread

Raja

Read only

0 Likes
3,222

Acutally why I have been trying it i.e. "& # x d ;" because I want to insert a line break. There's a particular XML tag which has text descriptions of hundreds of characters. So in order to display it as a well formatted description we are trying to insert line breaks (say after every 100 characters).

This is why the & is appearing within the XML. If you can give some idea to enable that it will really helpful.

Thanks a ton.

Vivek

Read only

0 Likes
3,222

ok, if thats the case you can simply do the following.

data: element_text type string .

concatenate `First Line' CL_ABAP_CHAR_UTILITIES=>CR_LF `Second Line` CL_ABAP_CHAR_UTILITIES=>CR_LF `Third Line` into element_text .

now use this variable (element_text) in the xml document.

Regards

Raja

Read only

0 Likes
3,222

Hi Raja

We've tried this. CL_ABAP_CHAR_UTILITIES=>CR_LF actually gives an SAP new line feed not an XML one. Say when we hit <ENTER> on Notepad it gives ASCII/Character Set new line, similarly in HTML document we use <BR> tag to infuse a new line. Hence in XML documents we need to use "& # x d ; & # x a ;" to get a new line when the XML parser (browser) parses the XML document.

We actually send this SAP generated XML document to a third party and the parsers in their system compile XML tags' data to generate requisitions in their system.

There's an XML tag we have in which we need to send some 4000 characters of descriptive data (long text). The text is spread out in mutiple lines and has certain type of formattings (line breaks). But we are not able to bring in these line breaks into the XML document so that the text lines appear in exactly similar new lines as in the original description. Hope you caught my idea.

Do let me know then. Thanks a lot once again for staying involved.

Regards.

Read only

0 Likes
3,222

Hi Raja

We've tried this. CL_ABAP_CHAR_UTILITIES=>CR_LF actually gives an SAP new line feed not an XML one. Say when we hit <ENTER> on Notepad it gives ASCII/Character Set new line, similarly in HTML document we use < B R > tag to infuse a new line. Hence in XML documents we need to use "& # x d ; & # x a ;" to get a new line when the XML parser (browser) parses the XML document.

We actually send this SAP generated XML document to a third party and the parsers in their system compile XML tags' data to generate requisitions in their system.

There's an XML tag we have in which we need to send some 4000 characters of descriptive data (long text). The text is spread out in mutiple lines and has certain type of formattings (line breaks). But we are not able to bring in these line breaks into the XML document so that the text lines appear in exactly similar new lines as in the original description.

Hope you've caught my idea. Do let me know then. Thanks a lot once again for staying involved.

Regards.

Vivek

Read only

giancarla_aguilar
Participant
0 Likes
3,222

Hello, Vivek.

I know it has been 5 years already but I have the same problem. Searching through SDN and Google, nothing comes close to your post.

I have an XML tag (from a long text) that should have line feeds. I used chars '&#10' or '&#xA' as line feed chars. Downloading it to a local XML file, shows them as is. But when I open the same file through Notepad, it shows '& a m p...

as you said. And Excel can not process the file when I import it. I have to edit in Notepad to remove the "amp" text and then it is imported to Excel successfully.

May I ask if you have found a solution to this?

Thanks a lot!

Read only

0 Likes
3,222

Hello SAP Friends!

I'm facing the same problem concerning special chars in XML. I've tried to unescape the '&' sign with methods of if_ixml_ostream

   l_ostream->set_ignore_escaping( ignore_escaping = '&' ).

the character is set and can be called by


  l_str = l_ostream->get_ignore_escaping( ).

After the rendering was done and the download has finished the xml document can be loaded in EXCEL but the special characters are replaced by & a m p;

Has anybody found a method to avoid the behaviour?

My original problem is, the the data have to be in one cell in excel. I know at present no method to download data (text including line feeds) from SAP to excel into one cell.

Maybe you have found a way to use  ignore_escaping in correct way!

Thanks a lot in advance!!!

Read only

Former Member
0 Likes
3,222

Hello,

I'm facing the same problem concerning special chars in XML. The issue is "&" being replaced by "& a m p ;".

Has anybody found a method to avoid the behaviour?

Best regards,

Patrice.