2015 Oct 08 6:21 PM
Hi All,
AM generating a XML document for a DDIC structure. I am able to generate the XML document but the customer requires the document in a specific format as shown below.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Import xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Row>
<License>1234</License>
<Distribution_Type>I</Distribution_Type>
</Row>
I have used the Call transformation method by creating a id in TCODE strans. The issue is, the first two lines of the document is as not expected.
How to achieve this ???
The first 2 lines are expected to be
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Import xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
but I get the following in my file
<?xml version="1.0" encoding="ISO-8859-1"?>
Regards
Arun
2015 Oct 08 7:36 PM
Hi Arunkumar,
This seems to be because of some special characters, ISO-8859-1” is the Latin-1 (western European languages) encoding.
There is one class available CL_XML_DOCUMENT using which you can set your desired encoding as below:
CREATE OBJECT m_document.
m_document->CREATE_EMPTY_DOCUMENT( ) .
m_document->set_encoding( CHARSET = 'UTF-8' ).
If above two not work then try to change any special character like & with & etc.
Below code taken from F1 help of CALL TRANSFORMATION
CALL TRANSFORMATION - transformation_options
Syntax
... OPTIONS [clear = val]
[data_refs = val]
[initial_components = val]
[technical_types = val]
[value_handling = val]
[xml_header = val] ... .
In OPTIONS of CALL TRANSFORMATION last parameter XML_HEADER
The transformation option xml_header controls the output of the XML header when transforming to XML and writing to a data object of type c, string, or to an internal table.
| Possible Values | Meaning |
| no | No XML header is output. |
| without_encoding | An XML header is output without specifying the encoding. |
| full | Default setting; an XML header is output, specifying the encoding. |
You can try passing this without_encoding option which will not generate any encoding.
Hope this will help.
Thanks-
Abhishek
2015 Oct 08 7:36 PM
Hi Arunkumar,
This seems to be because of some special characters, ISO-8859-1” is the Latin-1 (western European languages) encoding.
There is one class available CL_XML_DOCUMENT using which you can set your desired encoding as below:
CREATE OBJECT m_document.
m_document->CREATE_EMPTY_DOCUMENT( ) .
m_document->set_encoding( CHARSET = 'UTF-8' ).
If above two not work then try to change any special character like & with & etc.
Below code taken from F1 help of CALL TRANSFORMATION
CALL TRANSFORMATION - transformation_options
Syntax
... OPTIONS [clear = val]
[data_refs = val]
[initial_components = val]
[technical_types = val]
[value_handling = val]
[xml_header = val] ... .
In OPTIONS of CALL TRANSFORMATION last parameter XML_HEADER
The transformation option xml_header controls the output of the XML header when transforming to XML and writing to a data object of type c, string, or to an internal table.
| Possible Values | Meaning |
| no | No XML header is output. |
| without_encoding | An XML header is output without specifying the encoding. |
| full | Default setting; an XML header is output, specifying the encoding. |
You can try passing this without_encoding option which will not generate any encoding.
Hope this will help.
Thanks-
Abhishek
2015 Oct 08 8:27 PM
Hi Abhishek,
Thanks for your reply. The default code page in the system is ISO-8859-1.
I have used the set_encoding method to and now the xml gets generated as below
<?xml version="1.0" encoding="UTF-8"?>
But, the customer wants it as shown below
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Import xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
The first 2 lines should appear as shown above
Regards
Arun
2015 Oct 08 9:14 PM
Hi Arunkumar,
I checked the Class but could not find any relevant information on standalone = "yes" parameter.
Just curious why client needs this parameter do they use DTD instead of XML schema.
If they do use XML Schema then there is no meaning of defining standalone="yes". The default value for this parameter is "no".
From below second line I understood Client is using XML Schema and not DTD so I dont think you need standalone="yes".
REPLACE FIRST OCCURRENCE OF
'<?xml version="1.0" encoding="UTF-8"?>'
IN lv_xml
WITH
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Import xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
'.
This could be your final solution REPLACE.
Thanks-
Abhishek