How to read in an xml file created by c#

4 views (last 30 days)
Steven
Steven on 20 Apr 2016
Edited: Steven on 25 Apr 2016
I have an xml file, I would like to read it into matlab as a struct. The problem is, I know very little about xml. I know that the header file is supposed to define what it is
<xs:schema id="Blah" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="Blah" msdata:IsDataSet="true" msdata:Locale="en-US">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="treeItemsx" msdata:Locale="en-US">
<xs:complexType>
<xs:sequence>
<xs:element name="ItemID" type="xs:int" />
<xs:element name="Name" type="xs:string" minOccurs="0" />
<xs:element name="Type" type="xs:int" minOccurs="0" />
<xs:element name="FolderID" type="xs:int" minOccurs="0" />
<xs:element name="Value" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
Matlab can tranlate this but the problem is it cant translate entries like this:
<xs:unique name="_x0031__x002F_27_x002F_201510_x003A_23_x003A_35_x0020_PMSONYBFYHJI_Constraint1" msdata:ConstraintName="Constraint1" msdata:PrimaryKey="true">
<xs:selector xpath=".//_x0031__x002F_27_x002F_201510_x003A_23_x003A_35_x0020_PMSONYBFYHJI" />
<xs:field xpath="Name" />
</xs:unique>
I have tried xmlread and it fails on a file like this. I would like to be able to read a non-java xml file.
I would also be happy with being able to read sections of the file by reading it as a text file, but I am unsure how to do this.
  1 Comment
Steven
Steven on 20 Apr 2016
Edited: Steven on 20 Apr 2016
There is an old utillity called xmltoolbox that has a function called xml_parse and compiled it with pcode which wont work on newer versions of matlab. I'm looking for something with this functionality

Sign in to comment.

Answers (1)

Nikhil Vyas
Nikhil Vyas on 25 Apr 2016
If you provide proper starting and ending tags, it works properly with xmlread. I modified your first xml and added the second xml to the complexType section of the first. Here:
<xs:schema id="Blah" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="Blah" msdata:IsDataSet="true" msdata:Locale="en-US">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="treeItemsx" msdata:Locale="en-US">
<xs:complexType>
<xs:sequence>
<xs:element name="ItemID" type="xs:int" />
<xs:element name="Name" type="xs:string" minOccurs="0" />
<xs:element name="Type" type="xs:int" minOccurs="0" />
<xs:element name="FolderID" type="xs:int" minOccurs="0" />
<xs:element name="Value" type="xs:string" minOccurs="0" />
</xs:sequence>
<xs:unique name="_x0031__x002F_27_x002F_201510_x003A_23_x003A_35_x0020_PMSONYBFYHJI_Constraint1" msdata:ConstraintName="Constraint1" msdata:PrimaryKey="true">
<xs:selector xpath=".//_x0031__x002F_27_x002F_201510_x003A_23_x003A_35_x0020_PMSONYBFYHJI" />
<xs:field xpath="Name" />
</xs:unique>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
You can read the above with xmlread.
docX = xmlread('test.xml');
To test if it's working properly:
xmlwrite(docX)
  1 Comment
Steven
Steven on 25 Apr 2016
Edited: Steven on 25 Apr 2016
Xmlread doesn't work as I have already stated in the question, I already tried it. I need something that will read a section of the xmlfile because most of it is unreadable by xmlread.

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!