Hallo Forum,
ich habe analog zu dem u. a. Report entwickelt.
Das upload des XML Dokumentes und download funktionieren soweit.
Meine Frage : Wie kann ich das Dokument füllen bzw. ändern?
Es ist mit Sicherheit für einige von Euch sehr einfach aber mir fehlt leider das Abap Objects Wissen.
Danke im Voraus!
Code:
* 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.
include bcciixml_decl.
include bcciixml_impl.
*- 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 like rlgrap-filename.
filename = '\\p34218\public\orders2.xml'.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
FILENAME = filename
FILETYPE = 'BIN'
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:'.
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.
i = pParseError->get_column( ).
write: 'column: ', i.
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, '> '.
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.