How can I write multidimensional data to an XML-file?

4 views (last 30 days)
I would like to write multidimensional MATLAB arrays to an XML-file using XMLWRITE and the Document Object Model.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 7 Feb 2018
Binary data (such as multidimensional numeric arrays) are not easily encoded in XML, which is based around text and string tags. This issue is not specific to MATLAB; you can refer to an XML resource for more information.
There are several options for this sort of data:
1. Create a multi-level data structure. [1 2; 3 4] might be encoded as:
<row>
<item>1</item>
<item>2</item>
</row>
<row>
<item>3</item>
<item>4</item>
</row>
This is inefficient and laborious, but follows the XML structure.
2. Encode the binary data as a string using base64 or similar encoding, and include it as a block of data using CDATASection. The destination of the file must understand both the encoding and the binary representation used; this is usually possible for JPEGs or GIFs, but may be an issue choice for MATLAB data structures.
XML references may have additional suggestions. Because MATLAB uses the standard Java interface to XML, most information from generic Java XML resources also applies to XML in MATLAB.
A good DOM reference is:
 

More Answers (0)

Tags

No tags entered yet.

Products

Community Treasure Hunt

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

Start Hunting!