XRDMLread - Matlab function for reading X'Pert XRDML files

XRDMLwrite

Contents

First of all, those interested in XRD please excuse us. This page contains no simple Matlab XRDMLwrite function as a direct twin of the XRDMLread. The problem is discussed rather more generally and hopefully it may be of interest for all those engaged in XML, XMLTree and Matlab. Here we:

However, if you are looking for the XRDMLwrite and you will follow the recipe here, you can get a required solution – at least for Matlab, unfortunately not for Octave.


XMLTree2Doc.m - XMLTree conversion to Matlab Java DOM

XMLTree2Doc Matlab schema

Below we describe a method of conversion of the XMLTree objects representing XML-data into the native Matlab Java Document Object Model (DOM) format.

Why one need a such conversion?

  1. Some general purposes, e.g. one can do something easily with DOM that is difficult with XMLTree.
  2. A subset of the above group. One need to save data in a well formatted XML and it does not work with XMLTree itself for some reasons.

Practically these are more general problems with the XMLTree toolbox and it is not related only to the XRDMLread. As we are converting to the Matlab Java objects, it is also clear that this will not work in Octave(3.2).

Proposed conversion tool is a short recursive Matlab function: XMLTree2Doc.m.

The following code illustrates how to load an input XML-data (note.xml), modify the data using XMLTree toolbox, convert them to Matlab DOM with XMLTree2Doc and save the DOM document using a native Matlab function.

% XMLTree2Doc.m Example - XMLTree Conversion to Matlab Java DOM
xtree = xmltree( 'note.xml' ); % read xml data
xtree = set( xtree , children(xtree,find(xtree,'/note/body')) , ...
             'value' , 'And next week too!' ); % modify xmltree data
docNode = XMLTree2Doc( xtree ); % convert xmltree to DOM document
xmlwrite( 'new-note.xml' , docNode ) % save xml data

Please note also that our conversion function name ends with “Doc”, not with “Dom”.


XRDMLminimal.m - generating a minimal XRDML data

XRDMLwrite/XRDMLminimal Matlab schema

Now we can explain the particular problem of exporting data into an XRDML format with Matlab, XMLTree toolbox and XRDMLread. Actually, the present authors failed with X'Pert Data Viewer(vs. 1.2) in opening the XRDML-files exported by the “savexml” function from the XMLTree toolbox. As the Viewer is really a nice tool, this fatal problem discouraged any attempts of the XRDMLwrite implementation for a long time.

With XMLTree2Doc conversion tool the problem disappears. At least in Matlab. The XMLTree object can be converted to the Matlab Java DOM document, which is saved as a well formatted xml-file compatible with the X'Pert Viewer. Even the whole XRDML document can be generated using the XMLTree tools. XRDMLminimal.m is an example how to generate a minimal XRDML-file containing pre-calculated data. Only a piece of code is shown.

% XRDMLminimal.m - minimalistic XRDML data example
%
% Creates a minimal XRDML file containing pseudo-randomly generated
% data, which can be visualised directly with the X'Pert Data Viewer.

% create new xmltree object
xtree = xmltree;

% create root --- xrdMeasurements --- element
uid = root(xtree);
xtree = set( xtree, uid, 'name', 'xrdMeasurements' );
  % set attributes
  xtree = attributes( xtree, 'add', uid, 'xmlns', ...
                      'http://www.xrdml.com/XRDMeasurement/1.3');
  xtree = attributes( xtree, 'add', uid, 'xmlns:xsi', ...
                      'http://www.w3.org/2001/XMLSchema-instance');
  xtree = attributes( xtree, 'add', uid, 'xsi:schemaLocation', ...
                     ['http://www.xrdml.com/XRDMeasurement/1.3 ' ...
                      'http://www.xrdml.com/XRDMeasurement/1.3/XRDMeasurement.xsd']);
  xtree = attributes( xtree, 'add', uid, 'status', 'Completed');
  
% ... more code here ...


% save in an XML-file
docNode = XMLTree2Doc( xtree ); % convert to standard Matlab Java DOM document
xmlwrite( 'XRDMLminimal.xrdml' , docNode ); % save as an xml-file