.


   

Configuration File Transformation

Transforming a configuration file into a different form can have several uses. For example, a large configuration file can be split into several smaller files. Or, conversely, several configuration files can be merged into one.

meiConfig provides an interface to perform simple copy and remove transformations (see the –elemCopy and –elemRemove command line options).

More complex transformations can be made using any one of a number of techniques. Probably the most popular method of XML transformation is XSLT, a language for transforming XML documents into other XML documents. Implementations of XSLT are available for many languages, such as: C, C++, C#, Perl, Python, Ruby, PHP, Java, etc.

Another approach to XML transformation is to use a general purpose programming language along with SAX and/or DOM.

 

Example

Below is a description of the file axisSplitter.py, distributed in the meiConfig_lib directory. To download the file directly, click here.

The Goal

Read in a configuration file and output one or more configuration files, each of which contain a single Motion, Axis, Filter and Motor object. Each object is renamed as "Object 0." For example, the file for Axis 2 would include Motion 2 (renamed “Motion 0”), Axis 2 (renamed “Axis 0”), Filter 2 (renamed “Filter 0”) and Motor 2 (renamed “Motor 0”). All non-portable configuration elements, such as firmware addresses and object mappings, are stripped from the output.

The output files can be used to load configuration onto any set of Motion, Axis, Filter, and Motor objects. For example, if the utility produced the file, Axis0.xmc, it could then be downloaded to Motion 3, Axis 3, Filter 3, and Motor 3 using the following command:

  meiConfig –set –noTopocheck \
     –elemCopy Motion0,Motion3 \
     –elemCopy Axis0,Axis3 \
     –elemCopy Filter0,Filter3 \
     –elemCopy Motor0,Motor3 \
     –elemRemove Motion0 \
     –elemRemove Axis0 \
     –elemRemove Filter0 \
     –elemRemove Motor0 \
     Axis0.xmc

The –noTopocheck flag is necessary because the resulting output files will be stripped of all SynqNet topology information.

 

The Approach

The Python programming language is used along with xml.sax and xml.dom modules. The following items are defined:

Splitter - A general purpose class to create a DOM tree from an input XML file. The DOM tree will only contain the elements (and sub-elements) listed in an argument that were passed in at creation time.

main - This function performs the tasks of separating out the individual Motion, Axis, Filter, and Motor objects and creating the output files.

See axisSplitter.py for more details.


Previous | Next

       Legal Notice  |  Tech Email  |  Feedback
      
Copyright ©
2001-2009 Motion Engineering