Read XML files in pure Matlab, because xmlread is too slow.
Switch branches/tags
Nothing to show
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
MatlabXML.m adds copyright notice and documentation Mar 8, 2018
MatlabXMLElement.m adds copyright notice and documentation Mar 8, 2018
README.md adds copyright notice and documentation Mar 8, 2018

README.md

MatlabXML

Parses XML in pure Matlab

Given an XML file as test.xml:

<?xml version="1.0" encoding="UTF-8"?>
<content>
  <foo attr="bar"/>
</content>

You can read this file with

>>> xml = MatlabXML('test.xml')

ans = 

  MatlabXMLElement with properties:

          Name: '#document#'
    Attributes: [2x1 containers.Map]
      Children: [1x1 MatlabXMLElement]

which will return a MatlabXMLElement with three properties:

  • Name is the name of the element or document
  • Attributes are the attributes of the element as containers.Map
  • Children are the element's children as an array of MatlabXMLElement.

Why?

Why would you use this instead of Matlab's built-in xmlread?

  • xmlread is a horrible Java API that has no place in Matlab.
  • xmlread is extremely slow for large XML files.
  • xmlread will happily consume all your memory even if you max out your Java heap.

Why not?

Because MatlabXML does not support all of XML.

  • No support for CDATA.
  • No support for text nodes.
  • No support for DTD.
  • No verification whatsoever.

Examples:

>>> xml.Attributes('version')

ans = 

    '1.0'
   
>>> xml.Children

ans = 

  MatlabXMLElement with properties:

          Name: 'content'
    Attributes: [0x1 containers.Map]
      Children: [1x1 MatlabXMLElement]


>>> xml.Children(1).Children(1)

ans = 

  MatlabXMLElement with properties:

          Name: 'foo'
    Attributes: [1x1 containers.Map]
      Children: [1x0 Double]


>>> xml.Children(1).Children(1).Attributes('attr')

ans = 

  'bar'