NMPMLObject Class

Mien provides a correspondance between a collection of nested Python objects and an XML document. The XML dialect "nmpml" (Neural Model and Protocol Markup Language) provides the XML side of this system. Modules in sub-package mien.nmpml define the corresponding Python objects. All these objects derive from class NMPMLObject defined in mien.nmpml.basic_tools. This class inherits from BaseXMLObject, defined in mien.xml.xmlclass. The xml class provides an interface that is general to any xml dialect, and the nmpml class refines it with Mien-specific features. This distinction is relevant to developers who wish to resuse or extend core Mien, but not very relevant to users. It this document, both interfaces will be summarized together. All NMPML objects support this interface.

Data Members

The most important public data members of an nmpml object are container, attributes, elements, and cdata.

Container is either None (for the top-level element) or a reference to the element one step up in the hierarchy.

Cdata is a string containing the xml tag's cdata (if any)

Attributes is a dictionary mapping xml attributte names onto values. Mien performs a dynamic conversion of data types when translating to anf from XML. All xml attribute values are strings, but Mien attributes are python data types. The functions typeToString and stringToType in mien.nmpml.basic_tools implement the conversion. Essentially,basic types are converted by evaluation into the most restrictive possible type ("1"->int, "1.0"->float, "1.0cm"->string), and comma separated values are converted to python lists ("2,3.,s"->[2, 3.0, 's'] ). Data types more complicated than lists can't be reliably stored in xml (but they can be assigned to keys in the attributes member of a Python class).

Elements is a list of references to any elements contained in this element. Elements and container together provide a doubly-linked list that simplifies navigating xml trees.

Read access to class members is safe (although access through methods is often more convenient). Writing to data members is allowed, but not generally safe. Methods are provided for setting all data members and should be used. The Python philosophy is not to prohibit access, but instead to assume that "we are all consenting adults here". Thus, client code may write to class members directly if needed, but it is usually be a bad practice that most Pythoneers avoid by convention. In general, writing directly to object members leads to buggy hard-to-maintain code. In particular, doing so in MIEN will tend to break GUI screen update, undo, and checkpoint features, and may result in code that works well for local file access but won't work at all in a threaded or network environment, or when input files include data or instructions from remote urls or databases.

 

Last edit: 05/29/09

Index