Application Development 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: 

XML Simple transform for special characters

Former Member
0 Kudos

Greetings XML experts,

I am having an issue doing a simple transform (STRANS) in ABAP. I am having issues when some of the content of my elements contain special characters. ex:

<remarks>The sum of 8 is > 6, while 5 < 3</remarks>

<material>ABCD&1234</material>

The special characters <, &, > are not being recognized and causing an exception. Is there some XML command that allows the special characters? Something that I could add to my command ex:

<tt:cond>

     <remarks tt:value-ref="zremarks"/>

</tt:cond>

<tt:cond>

     <material tt:value-ref="zmaterial"/>

</tt:cond>

Thanks!

1 ACCEPTED SOLUTION

former_member198833
Active Participant
0 Kudos

Hi Bill,

Since XML cannot handle special characters, you should use the escape characters.

So, element "&" should be replaced with "&amp". "<" (Less than) should be converted to "&#60" and ">" (Greater than) to "&#62".

Regards,

Felipe

6 REPLIES 6

former_member198833
Active Participant
0 Kudos

Hi Bill,

Since XML cannot handle special characters, you should use the escape characters.

So, element "&" should be replaced with "&amp". "<" (Less than) should be converted to "&#60" and ">" (Greater than) to "&#62".

Regards,

Felipe

0 Kudos

Felipe,

Thanks for the response. I changed my string to look for '&' and replace with '&amp', but this still fails during the simple transform. Any thoughts? Thanks.

0 Kudos

You must replace with '&amp;' (with a semicolon at the end; ignore the quotes) ; the worst character for the parser is '<' ; see Raymond answer.

0 Kudos

Yes, with xml start replacing '&', '<' and '>' then perform some tests as some other entities could be required?

0 Kudos

Sandra,

I was able to use the &amp; with success. I was missing the ' ; ' . thanks for the help with that. The < > is going to be a real pain I am guessing.

raymond_giuseppi
Active Contributor

Replace every special characters with some xml/html entities:

Sample for some basic html entities, but google for list, depend also on languages in use...


REPLACE ALL OCCURRENCES OF '&'  IN text WITH  '&amp;'  IGNORING CASE.

REPLACE ALL OCCURRENCES OF '"'  IN text WITH  '&quot;' IGNORING CASE.

REPLACE ALL OCCURRENCES OF '<'  IN text WITH  '&lt;'   IGNORING CASE.

REPLACE ALL OCCURRENCES OF '>'  IN text WITH  '&gt,'   IGNORING CASE.

REPLACE ALL OCCURRENCES OF '©'  IN text WITH  '&copy;' IGNORING CASE.

Regards,

Raymond