Case Study: Developing a Reading List ADT | 12.3
12.3 Case Study: Developing a Reading List ADT
Now thatyou have some understanding of what XML is all about, we can begin to
develop some examples that use the iXML libraiy. In this section, we will begin
by developing an abstract data type (ADT) class to represent the reading list exam-
ple described in Section 12.1.2, Understanding XML Syntax. Here, we want to
stay consistent with our object-oriented design principles by encapsulating the
XML details inside the class.
Throughout the course of this book, we have typically represented the internal
state of the classes using basic ABAP data types. However, while this approach is
often convenient, it is not a hard requirement. For example, in the case of our
Reading List class, we will prefer to store the list in a DOM-based data structure.
Of course, good object-oriented design principles will ensure that these details
are hidden from the end user.
The UML class diagram shown in Figure 12.3 shows the core iXML classes and
interfaces that we will be using to develop our Reading List class.
As
you can see.
the iXML library makes heavy use of interfaces. In fact, the iXML design is a clas-
sic example of the principle of programming to an interface. The basic idea here is
to provide an API based on generic interfaces rather than concrete implementa-
tions. This gives SAP the flexibility to change the way the iXML library is imple-
mented (perhaps by plugging in a different XML parser, etc.) without affecting
users of the API.
The starting point for working with the iXML libraiy is the core I
F_I XML
interface.
You can obtain a reference to an object that implements this interface by calling
the class method
CREATE
of factory class
CL_IXML.
As you can see in Figure 12.3,
the I
F_L XHL
interface defines a series of factoiy methods that can be used to
obtain references to various objects and services within the iXML libraiy.
After you have a reference to the I
F_I XML
factory object, you have two options for
creating a DOM-based XML document:
• If you want to load an XML document from an external data source (e.g.. a file),
you must first read that document into an input stream and then parse it using
the XML parser provided with the iXML library. You can obtain references to
the IF_IXML_ISTREAM and
IF_IXML_PARSER
objects using the instance methods
CREATE_STREAM_FACTORY
and
CREATE_PARSER
of interface
IF_IXML.
311