XML bindings
From ESEwiki
XML bindings can be created using the eseb tool (Enterprise SmartEiffel Binder), using a DTD file (XML schemas to be supported later).
Contents |
Synopsis
- se eseb --help
- se eseb [--verbose] [--directory <output directory>] [--prefix <class prefix>] <DTD file>
The options are:
| --help | Give help on the tool usage |
| --verbose | Tell the tool to talk about what it does (default is be quiet and just do the job) |
| --directory <output directory> | Specify the directory where the generated classes should be put (default is the current directory) |
| --prefix <class prefix> | Specify a prefix for the generated classes (default is no prefix) |
| <DTD file> | Specify the DTD file to read |
Usage
The DTD file contains elements and attributes.
Elements
The elements are directly converted into classes; for instance <!ELEMENT foo #PCDATA> creates a class named FOO (or PREFIX_FOO if --prefix PREFIX was used). Each created class is a direct heir of VISITABLE.
The visitor is also generated; it is named after its visiting class, suffixed by _VISITOR and holds one feature called visit_ followed by the element class name in lower-case.
A simple element:
<!ELEMENT root node*>
will be generated as:
class interface ROOT
feature {ANY}
node (i: INTEGER): NODE
end
There can be anonymous lists; they are generated as alternative classes. For example, the following:
<!ELEMENT node (node|data)*>
will use an alternative:
class interface NODE
feature {ANY}
alternative (i: INTEGER): ALTERNATIVE_NODE
end
class interface ALTERNATIVE_NODE inherit VISITABLE end
class interface ALTERNATIVE_NODE_0
inherit
ALTERNATIVE_NODE
feature {ANY}
child: CHILD
end
class interface ALTERNATIVE_NODE_1
inherit
ALTERNATIVE_NODE
feature {ANY}
data: DATA
end
You distinguish between alternatives by using visitors (alternatives are visitable).
Attributes
The attributes are put in a dictionary. There is a single getter for all attributes (attribute), which takes a STRING (the attribute name) and returns a STRING (the attribute value). The internal code is a string inspect. The precondition is known_attribute.
In the same way, there is only one setter (set_attribute) which sets the attribute value. The precondition is also known_attribute.
For instance, <!ATTLIST foo bar CDATA #REQUIRED> generates the inspect branch "bar" in the method attribute of the class FOO. It also generates an argument a_bar to the make constructor, because the attribute is required. Furthermore, the invariant will state that
attribute(once "bar") /= Void
The parser
The parser name is the prefix followed by the name of the DTD. It inherits from XML_TREE and can be used as such. The constructor is make.
A complete example
The DTD file
<!ELEMENT root data*,child* > <!ELEMENT data PCDATA > <!ELEMENT child EMPTY > <!ATTLIST data id #CDATA REQUIRED > <!ATTLIST child refid #CDATA REQUIRED >
The TREE_PARSER class
TODO:
eseb tree.dtd
The ROOT class
TODO:
eseb tree.dtd
The DATA class
TODO:
eseb tree.dtd
The CHILD class
TODO:
eseb tree.dtd

