cancel
Showing results for 
Search instead for 
Did you mean: 

XML conversion special characters.

Former Member
0 Kudos

Hi,

I need to convert an XML containing special characters like & ' < to the XML codification (&amp,&apos, ..).

I'm having an XML like this :

<?xml version=''1.0'' encoding=''UTF-8''?>

<ROOT xmlns:sql=''urn:schemas-microsoft-com:xml-sql'' >

<sql:query>

select * from table where field = '1241&'

</sql:query>

</ROOT>

I tried to use the class cl_xml_document.

here is part of the code :

CALL METHOD lo_mxml->parse_string

EXPORTING

stream = xmlbody.

CALL METHOD lo_mxml->render_2_string

EXPORTING

PRETTY_PRINT = 'X'

IMPORTING

RETCODE = lv_Retcode

STREAM = lv_String

SIZE = lv_size.

CALL METHOD lo_mxml->display.

the result is :

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

<ROOT xmlns:sql="urn:schemas-microsoft-com:xml-sql">

<sql:query>

SELECT * FROM table where field = &apos;1

</sql:query>

</ROOT>

the rendering stops after having replaced the first special characters. any idea ? or another way for doing that ?

any help will be appreciated.

thanks,

regards,

Abdelaltif

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Were you able to resolve this issue?

I am having similar situation in my XML files.

  • wrap the table containing the file into a stream

G_ISTREAM = G_STREAMFACTORY->CREATE_ISTREAM_ITABLE( TABLE =

T_XML_TABLE

SIZE = G_LEN ).

  • Creating a document

  • Before creating the XML DOM object, you have to create an empty doc

  • and a parser object. The document object will represent the DOM

  • object and the parser is needed to convert the XML stream into

  • a XML DOM object.

G_DOCUMENT = G_IXML->CREATE_DOCUMENT( ).

  • Create a Parser

G_PARSER = G_IXML->CREATE_PARSER( STREAM_FACTORY = G_STREAMFACTORY

istream = G_ISTREAM

DOCUMENT = G_DOCUMENT ).

  • Parse the stream

DATA: RTN TYPE I .

RTN = G_PARSER->PARSE( ) . (It stops/freezes here). I think it is to do with some special characters. Not sure how to resolve this.

You can contact me at cjrajesh@hotmail.com

Appreciate your help as this is pretty critical for our go-live.

Regards,

Rajesh

athavanraja
Active Contributor
0 Kudos

as you mentioned earlier you have to convert the & to &amp;

concatenate

`<?xml version='1.0' encoding='UTF-8'?>`

`<ROOT xmlns:sql='urn:schemas-microsoft-com:xml-sql' >`

`<sql:query>`

`select * from table where field = <b>'1241&amp;'`</b>

`</sql:query>`

`</ROOT>` into xml_out .

i was looking for a utility class withing ABAP to do this kind of conversion but didnt find anything so far.

If i come across anything i will let you know.

Regards

Raja

athavanraja
Active Contributor
0 Kudos

hows the xml received into your program?

convert the input xml string to a xstring and try?

Regards

Raja

Former Member
0 Kudos

HI Raja,

thanks for the suggestion but it didn't work .

regards,

Abdellatif