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: 

Create XML on SAP

former_member1038687
Active Participant
0 Kudos

Hi friends! I need some help!

I'm creating an XML file with the code:

g_ixml = cl_ixml=>create( ).

g_document = g_ixml->create_document( ).

lote = g_document->create_simple_element(
                   name = 'NF'
                   parent = g_document ).

nfnum = g_document->create_simple_element(
                               name  = 'nfnum'
                               value = '999999999'
                               parent = lote ).

*   Creating a stream factory and streams
g_streamfactory = g_ixml->create_stream_factory( ).

g_encoding = g_ixml->create_encoding(
                      character_set = c_encoding
                      byte_order = if_ixml_encoding=>co_little_endian ).

* Rendering into a table-based stream
g_ostream = g_streamfactory->create_ostream_itable( xml_table ).

g_ostream->set_encoding( encoding = g_encoding ).

g_renderer = g_ixml->create_renderer( ostream  = g_ostream
                                      document = g_document ).
g_rc = g_renderer->render( ).

* use only the first xml_size bytes of the xml table!!
xml_size = g_ostream->get_num_written_raw( ).

data: v_file type string.

concatenate 'C:\' 'FUL01' '.txt' into v_file.

call method cl_gui_frontend_services=>gui_download
  EXPORTING
    bin_filesize = xml_size
    filename     = v_file
    filetype     = 'BIN'
  CHANGING
    data_tab     = xml_table.

It's worked, but all tags is writed in same line:

<?xml version="1.0" encoding="utf-8"?><NF><nfnum>999999999</nfnum></NF>

So, I want something like:

<?xml version="1.0" encoding="utf-8"?>
             <NF>
                    <nfnum>999999999</nfnum>
             </NF>

How can I do this?

Thanks for any help!

1 ACCEPTED SOLUTION

rainer_hbenthal
Active Contributor
0 Kudos
method set_pretty_print

This method specifies whether the stream should suppress new-lines and indentation for the output.

interface

if_ixml_ostream

parameters

pretty_print [ default 'X' ]

False, if the new-lines and indentation should be suppressed, true otherwise.

abap signature

method set_pretty_print

importing

pretty_print type boolean default 'X'.
8 REPLIES 8

Former Member
0 Kudos

Hi,

Instead of concatenate 'C:\' 'FUL01' '.txt' into v_file. Try to give concatenate 'C:\' 'FUL01' '.xml' into v_file.

I mean replace .txt with .xml and check how it works.

Basically when we download the xml file when it is XML format then we will get the output as expected by you

since the format will be taken care by .XML itself.

Hope this will resolve your issue.

Regards

VEnk@

Edited by: Venkat Reddy on Nov 17, 2009 5:56 PM

Edited by: Venkat Reddy on Nov 17, 2009 6:12 PM

0 Kudos

Thanks for quick reply Venkat Reddy!

I done this and opend in IE8 and work fine, but I have a problem. The legacy system that I'll export want a XML format, but in a TXT filename, because of this I'm downloading with a TXT extension.

I don't know if I sent it into a single line if it will work...

0 Kudos

Hi,

Have you changed the .txt to .XML format ? If yes the XML file will be downloaded into

the path that you have mentioned. Maybe any number. If you want any name specification

for each XML file tht u have downloaded then jus use the below line,,

concatenate 'C:\' docnum sy-datum sy-uzeit '.xml' into filename SEPARATED BY SPACE.

Now in C: drive may be how many number of XML files you download they will be with unique

Docnum with date and time.

Make me clear of this Line "My problem is generating file like this name in TXT." wht actually you mean

by this.

Regards

VEnk@

Edited by: Venkat Reddy on Nov 17, 2009 6:26 PM

0 Kudos

Sorry! I will try to be more cleary.

The file has to have extension ".TXT" to legacy system process it, but the internal structure have to be XML. In sample of legacy system that I posted, the file has extension ".TXT", so, when I open it on notepad the xml code is Ok, indented TAGs like when I open in IE8. Bellow the file NF00232.TXT:

<?xml version="1.0" encoding="UTF-8"?>			
<reqNFeEmi xmlns="http://www.synchro.com.br/nfe" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.synchro.com.br/nfe
synNFeEmissaoRequest_v1.10.xsd" versao="1.10">
	<sistOrigem>FATURAMENTO</sistOrigem>
	<idLoteOrigem>0</idLoteOrigem>
	<NFe>
		<infNFe versao="1.10">
			<ide>
				<cUF>35</cUF>
				<natOp>String</natOp>
				<indPag>0</indPag>
				<mod>55</mod>
				<serie>1</serie>
				<nNF>420051</nNF>
				<dEmi>2009-09-20</dEmi>
				<dSaiEnt>2009-09-20</dSaiEnt>
				<tpNF>1</tpNF>
				<cMunFG>3550308</cMunFG>
				<tpImp>2</tpImp>
				<tpEmis>N</tpEmis>
				<chaveOrigem>cv420051</chaveOrigem>
			</ide>

When I open in notepad show this and not in one line like mine. So I'm trying to generate a file with extension .TXT, but the internal in XML like sample above.

pepl
Active Participant
0 Kudos

Hi!

I am not completely sure, but may be this method will help

g_ostream->set_pretty_print( ).

0 Kudos

I tried this but in TXT still in one line only. When I rename to .XML and open in IE8 works.

I have here sample of the file of legacy system in .TXT:

<?xml version="1.0" encoding="UTF-8"?>			
<reqNFeEmi xmlns="http://www.synchro.com.br/nfe" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.synchro.com.br/nfe
synNFeEmissaoRequest_v1.10.xsd" versao="1.10">
	<sistOrigem>FATURAMENTO</sistOrigem>
	<idLoteOrigem>0</idLoteOrigem>
	<NFe>
		<infNFe versao="1.10">
			<ide>
				<cUF>35</cUF>
				<natOp>String</natOp>
				<indPag>0</indPag>
				<mod>55</mod>
				<serie>1</serie>
				<nNF>420051</nNF>
				<dEmi>2009-09-20</dEmi>
				<dSaiEnt>2009-09-20</dSaiEnt>
				<tpNF>1</tpNF>
				<cMunFG>3550308</cMunFG>
				<tpImp>2</tpImp>
				<tpEmis>N</tpEmis>
				<chaveOrigem>cv420051</chaveOrigem>
			</ide>

If I change extension to .XML and open in IE8, works fine to, like my file renamed to.XML. My problem is generating file like this name in TXT.

former_member435013
Active Participant
0 Kudos

Hi,

I think xml in one line is normal.

I use Microsoft XML Notebook2007 for viewing and maintenance.

with kind regards

Walter Habich

rainer_hbenthal
Active Contributor
0 Kudos
method set_pretty_print

This method specifies whether the stream should suppress new-lines and indentation for the output.

interface

if_ixml_ostream

parameters

pretty_print [ default 'X' ]

False, if the new-lines and indentation should be suppressed, true otherwise.

abap signature

method set_pretty_print

importing

pretty_print type boolean default 'X'.