How to read in an xml file created by c#

조회 수: 4 (최근 30일)
Steven
Steven 2016년 4월 20일
편집: Steven 2016년 4월 25일
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
Steven
Steven 2016년 4월 20일
편집: Steven 2016년 4월 20일
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

댓글을 달려면 로그인하십시오.

답변 (1개)

Nikhil Vyas
Nikhil Vyas 2016년 4월 25일
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
Steven
Steven 2016년 4월 25일
편집: Steven 2016년 4월 25일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Structured 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