on 06-09-2008 3:41 PM
Hi experts,
I have used adobe forms.then i want to convert XML to ABAP internal table & vice versa...I searched sdn before posting this thread.
I am new to adobe forms...All are giving code for XML to ABAP...I could not understand the code directly...
Can any one tel me...how to convert XML to ABAP using Simple transformation... Please tel me the descriptive way of Converting XML to ABAP.
Thanks & regards,
Mathi
Hi,
Call transformation didn't work for me so I decided to implement BCC.
You can try to test this demo program:
*
BCCIIXMLT1 - sample program
*
This sample program shows how to read an XML document from a file
in the frontend's file system, parse the document into a DOM
representation and display the content as a list.
Additionally the DOM representation is rendered back into an XML
stream and stored as an output XML file on the frontend machine.
*
This sample program uses ABAP tables to represent the XML input
and output streams. See BCCIIXMLT2 for a sample using strings.
*
report BCCIIXMLT1 message-id bcciixmlt3_msg line-size 1000.
type-pools: ixml.
*- test program -
start-of-selection.
*-- data
data: piXML type ref to if_ixml,
pDocument type ref to if_ixml_document,
pStreamFactory type ref to if_ixml_stream_factory,
pIStream type ref to if_ixml_istream,
pParser type ref to if_ixml_parser,
pNode type ref to if_ixml_node,
pText type ref to if_ixml_text,
string type string,
count type i,
index type i,
totalSize type i,
dsn(40) type C,
xstr type xstring.
*-- read the XML document from the frontend machine
types: begin of xml_line,
data(256) type X,
end of xml_line.
data: xml_table type table of xml_line.
data: filename type string.
filename = '
p34218\public\class.xml'. "#EC NOTEXT
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = filename
FILETYPE = 'BIN' "#EC NOTEXT
IMPORTING
FILELENGTH = totalSize
TABLES
DATA_TAB = xml_table
EXCEPTIONS
OTHERS = 11
.
if sy-subrc <> 0.
message w000.
exit.
endif.
*-- create the main factory
pixml = cl_ixml=>create( ).
*-- create the initial document
pDocument = pixml->create_document( ).
*-- create the stream factory
pStreamFactory = pixml->create_stream_factory( ).
*-- create an input stream for the table
pIStream = pStreamFactory->create_istream_itable( table = xml_table
size = totalSize ).
*-- create the parser
pParser = piXML->create_parser( stream_factory = pStreamFactory
istream = pIStream
document = pDocument ).
*-- parse the stream
if pParser->parse( ) ne 0.
if pParser->num_errors( ) ne 0.
count = pParser->num_errors( ).
write: count, ' parse errors have occured:'. "#EC NOTEXT
data: pParseError type ref to if_ixml_parse_error,
i type i.
index = 0.
while index < count.
pParseError = pParser->get_error( index = index ).
i = pParseError->get_line( ).
write: 'line: ', i. "#EC NOTEXT
i = pParseError->get_column( ).
write: 'column: ', i. "#EC NOTEXT
string = pParseError->get_reason( ).
write: string.
index = index + 1.
endwhile.
endif.
endif.
*-- we don't need the stream any more, so let's close it...
call method pIStream->close( ).
clear pIStream.
**-- render the DOM back into an output stream/internal table
*data: pOStream type ref to if_ixml_ostream.
*pOStream = pStreamFactory->create_ostream_itable( table = xml_table ).
*call method pDocument->render( ostream = pOStream ).
**-- how many bytes were written to the table?
*totalSize = pOStream->get_num_written_raw( ).
*
*
**-- write the XML document back to the frontend
*concatenate filename '.out' into filename.
*condense filename no-gaps.
*CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
BIN_FILESIZE = totalSize
FILENAME = filename
FILETYPE = 'BIN'
TABLES
DATA_TAB = xml_table
EXCEPTIONS
OTHERS = 11
.
*IF SY-SUBRC <> 0.
*ENDIF.
*-- print the whole DOM tree as a list...
pNode = pDocument.
perform print_node using pNode.
----
FORM print_node *
----
........ *
----
form print_node using value(pNode) type ref to if_ixml_node.
data: indent type i.
data: pText type ref to if_ixml_text.
data: string type string.
indent = pNode->get_height( ) * 2.
case pnode->get_type( ).
when if_ixml_node=>co_node_element.
string = pNode->get_name( ).
write: at /indent '<', string, '> '. "#EC NOTEXT
when if_ixml_node=>co_node_text.
pText ?= pNode->query_interface( ixml_iid_text ).
if pText->ws_only( ) is initial.
string = pNode->get_value( ).
write: at /indent string.
endif.
endcase.
pNode = pNode->get_first_child( ).
while not pNode is initial.
perform print_node using pNode.
pNode = pNode->get_next( ).
endwhile.
endform.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.