MXML

バージョン 2.0.0.0 (216 KB) 作成者: TADA
Xml export\import for OO-matlab
ダウンロード: 109
更新 2018/10/23

ライセンスの表示

MXML package (Matlab-XML) is a standalone package designed for serializing
and deserializing objects(structs\classes) into\from XML\Json files. This format is useful
for transfering a complete object model between Matlab and other working environments,
such as .Net, Java, Javascript, Python, etc.
Parsing DOM objects to structs was taken from:
https://www.mathworks.com/help/matlab/ref/xmlread.html

***************************************************************************
Main methods:
obj = MXML.load(filePath, [format]) (format = 'json' or 'xml')
obj = MXML.load(xmlOrJsonString, format)
MXML.save(filePath, obj, [format])
MXML.toxml(obj)
MXML.tojson(obj)

The load\save\toxml methods have a functionality for saving a data object and a metadata object in the same file.
when saving to/loading from file, format is optional, if format is not specified, it will be decided from the file extension:
.json for json format and anything else for xml format

The package has a builtin class factory, which instantiates according to class name.

***************************************************************************
The general format of the generated XML looks like this:
<document type="struct">
<data type="struct">
<propertyName1 type="propertyType1" [isList="true"]>
[Content]
</propertyName1>
<propertyName2 type="cell" isList="true">
<entry type="entryType1" [isList="true"]>[Content]</entry>
<entry type="entryType2" [isList="true"]>[Content]</entry>
<entry type="entryType3" [isList="true"]>[Content]</entry>
</propertyName2>
<propertyName3 type="propertyType3" [isList="true"]>
[Content]
</propertyName3>
</data>
</document>

***************************************************************************
Saving to Json format:
The regular object graph will be stripped of data-types once serialized
to JSON format.
In this implementation primitive types such as numerics, logicals,
char-arrays, do not recieve the added typing convention to minimize the
object graph and the json size. This however removes the type
reversibility of these types, i.e, int and double are treated similarly
thus when parsing back from json, int32 types will be parsed into double
and so on.

for instance:
a = struct('id', '', 'children', struct('name', {'a', 'b'}, 'value', {1, 2}), 'class', someClassDef)

jsonizes into the following object graph:
a = struct('id', ''),...
'children', struct('type', 'struct', 'isList', true, 'value', [struct('name', 'a', 'value', 1), struct('name', 'b', 'value', 2)],...
'class', struct('type', 'someClassDef', 'value', struct(all properties of someClassDef))

which in turn is encoded into this json:
{ "id":"",
"children":{"type":"struct", "isList":true, "value":[{"name":"a", "value":1},
{"name":"b", "value":2}]},
"class":{"type":"someClassDef", "value":{"prop1":value1,"prop2":value2,...}} }

引用

TADA (2024). MXML (https://www.mathworks.com/matlabcentral/fileexchange/67966-mxml), MATLAB Central File Exchange. 取得済み .

MATLAB リリースの互換性
作成: R2015a
すべてのリリースと互換性あり
プラットフォームの互換性
Windows macOS Linux
カテゴリ
Help Center および MATLAB AnswersCall Web Services from MATLAB Using HTTP についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
バージョン 公開済み リリース ノート
2.0.0.0

Added serialization to/loading from xml string
Added all functionality for Json format
IIterable no longer sends data struct to ctor, rather now it works as intended, where the data entries are added to the list using the IIterable API.

1.0.0.0

Description updated again
Description updated