Show TOC Anfang des Inhaltsbereichs

Hintergrunddokumentation Basic steps in your program  Dokument im Navigationsbaum lokalisieren

This section describes the main steps required when using the iXML library.

Creating the main iXML factory

The first thing to do in your source code using the iXML library is to include the following two lines - typically in your initialization code.

type-pools: ixml.

class cl_ixml definition load.

The next step is creating the main factory for the iXML library:

data: g_ixml type ref to if_ixml.

g_ixml = cl_ixml=>create( ).

You will need only one such factory in a program, so it makes sense to place the statement above in the initialization section of your program and make g_ixml a global variable. If you try to instantiate the iXML factory more than once in a program, you'll only get references to the first instance created (singleton).

Now you are already done. The iXML library is ready for use and the next steps depend on what you actually want to accomplish.

Creating a stream factory and streams

Usually your program will require some form of input or output. The iXML library therefore provides a number of different streams you can use for XML document I/O. The object that constructs these streams is an cl_ixml_stream_factory object, which can be created by the iXML factory with the following statement:

data: streamFactory type ref to if_ixml_stream_factory.

streamFactory = g_ixml->create_stream_factory( ).

Now you are ready to create e.g. an input stream that can be used to read from a file in your machine's file system:

data: iStream type ref to if_ixml_istream.

iStream = streamFactory->create_istream_uri( "file://c:\public\test.xml" ).

Or you can wrap an internal (unstructured) table into a stream to pass it to the parser. The table is then assumed to contain a line-wrapped XML document:

types: begin of xml_line,

        data(256) type x,

      end of xml_line.

 

data: xml_table      type table of xml_line,

      xml_table_size type i,

      istream        type ref to if_ixml_istream.

 

* upload a file from the client's workstation

call function 'WS_UPLOAD'

     exporting

          filename                = '\\p34218\public\test.xml'

          filetype                = 'BIN'

     importing

          filelength              = xml_tablesize

     tables

          data_tab                = xml_table

     exceptions

          others                  = 11.

 

* wrap the table containing the file into a stream

istream = streamFactory->create_istream_itable( table = xml_table

                                                size  = xml_tablesize ).

 

When parsing an XML document you will simply pass the stream to the parser. The actual source behind the stream doesn't matter. For a list of available streams check the if_ixml_stream_factory interface.

Creating a document

No matter whether you parse an XML document or create one from scratch with your program and then render it into a stream, you always need some object to store the document for you while you handle it with your code. The object you need is an cl_ixml_document object and it's easy to get one from the iXML factory:

data: document type ref to if_ixml_document.

document = g_ixml->create_document( )

You can of course have several cl_ixml_document objects in parallel.

Now you are ready to get your hands dirty and parse an XML document. The next section will tell you how...




 

 

 

 

Ende des Inhaltsbereichs