Import .XML data into Matlab?

36 ビュー (過去 30 日間)
A
A 2016 年 3 月 2 日
回答済み: Faisal 2024 年 10 月 4 日
Hi guys,
I want to import an xml file and its data into matlab so that I can read the data.
I know you have to do something like: xDoc = xmlread('info.xml');
But I don't know much else after that. What code would I need to write to get the 'Customer' details from a .xml file with following content?
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<Shop Target="Something" Source="Something else">
<Customer ID="" LastName="Smith" FirstName="Joe" Birthday="1950/01/01" Gender="male">
<Purchase Type="Type 1" Time="2016/02/23 09:45" />
<Purchase Type="Type 2" Time="2016/02/24 09:45" />
</Customer>
</Shop>
Thank you

回答 (3 件)

per isakson
per isakson 2016 年 3 月 3 日
編集済み: per isakson 2016 年 3 月 3 日
In the File Exchange there are many contributions to read XML-files. Maybe, that's because xmlread is tricky to use.
I once chose xml2struct by Wouter Falkena, which handles my simple xml-files nicely. ( There is also a struct2xml.)
x = xml2struct( 'h:\m\cssm\cssm.xml' )
>> x
x =
Shop: [1x1 struct]
>> x.Shop
ans =
Customer: [1x1 struct]
Attributes: [1x1 struct]
>> x.Shop.Customer.Purchase{1}
ans =
Text: [1x0 char]
Attributes: [1x1 struct]
>> x.Shop.Customer.Purchase{1}.Attributes
ans =
Time: '2016/02/23 09:45'
Type: 'Type 1'
where cssm.xml contains the text of your question

Navjot Kaur
Navjot Kaur 2019 年 12 月 9 日
Can we read/import .XML file directly into MATLAB?

Faisal
Faisal 2024 年 10 月 4 日
You can use the built-in function readstruct('filename.xml')

カテゴリ

Help Center および File ExchangeStructured Data and XML Documents についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by