how to use xmlread in a very simple example

19 views (last 30 days)
I would like a very simple example for reading numeric data from a xml file using xml read. I would like the xml file to be something like:
<!-- This is a simple xml file containing data -->
<file>
<data>
<variable1>100</variable1>
<variable2>200</variable2>
</data>
</file>
  4 Comments
Adam Danz
Adam Danz on 12 Jul 2018
doc xmlread
shows simple examples that you're requesting.
Bruce McWhorter
Bruce McWhorter on 12 Jul 2018
Edited: Guillaume on 12 Jul 2018
Thanks. Yes, I have been reading more on this subject and now understand a lot more.
I needed to at least state the following on the first line of the file: <?xml version="1.0" encoding="utf-8"?>
Some good advice I received is to use the matlab function "xml2struct", which I have done and that seems to do what I needed.

Sign in to comment.

Accepted Answer

Guillaume
Guillaume on 12 Jul 2018
I would recommend you use xml2struct to save you having to navigate the xml DOM returned by xmlread.
xml = xml2struct(yourxmlfile);
xml.file.data.variable1
xml.file.data.variable2

More Answers (0)

Products


Release

R2016a

Community Treasure Hunt

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

Start Hunting!