Ask Reuben

om Versus xml

What is difference between om and xml packages? 

When should you use om or xml?

When working with and manipulating XML data and files, a question gets asked as to wether to use the om package, or the xml package.  To understand the difference between these packages, you need to go back into Genero history.

At Genero’s birth, there was only the om package, the xml package was introduced later in version 2.10.  Also at Genero’s birth there was barely any ui.Dialog or ui.Form methods to allow you to make changes at runtime to the User Interface.  Instead the developer was expected to write their own library routines to manipulate the AUI Tree.   The om package served to allow developers to write these library routines, it contained enough functionality to allow a developer to traverse the AUI Tree (which is xml) and manipulate it.   An example of “enough functionality” was the limited XPath syntax in the om.DomNode.selectByPath method.

Examples of such library routines to manipulate the AUI Tree can be seen in this GitHub repository file.  This file makes changes or read the AUI Tree where there is no formal ui.Dialog, ui.Form etc method.  You will see frequent use of om.DomNode datatypes and methods in this code as it finds the appropriate node in the AUI Tree and sets or gets an attribute value.

In Genero 2.10 the xml package was added to give developers a full range of functionality to use when working with xml files and data similar to what can be found with other development tools.  This has a fuller range of XML functionality including use of namespaces.    You also see the fuller range in its xml.DomDocument.selectByPath method which conforms to the XPath 1.0 standard.

If you are writing library routines to work with the AUI Tree, you will find that the om package is required.  If you are working with XML data, XML files your first instinct should be to use the xml package.  You may find that you have old code using the om package to work with XML files and data that was written before the xml package was available, and chances are it works perfectly fine and will continue to do so.  If you decide to rewrite some code from om to xml, there is a documentation page that gives some advice and a mapping.