简体   繁体   中英

Create class from xml file in c#.net

i have a xml file with following structure,

<TestClass>
  <TestChildClass>
    <TestName Name="sample">
      <Table Name="table1" IdentityColumnName="RollNo" IntColumn="Mark" CharColumn="Name" >
        <Table Name="table2" IdentityColumnName="RollNo" IntColumn="SubjectCode" CharColumn="Subject" ReferenceColumn ="RollNo" >
            <Table Name="table3" IdentityColumnName="RollNo" IntColumn="Average" CharColumn="Subject" ReferenceColumn ="SubjectCode"/>          
         </Table>

        <Table Name="table4" IdentityColumnName="RollNo" IntColumn="Rank" CharColumn="Name" />
      </Table >
    </TestName >    
  </TestChildClass>
  </TestClass>

i have created a class for the above xml using XSD.EXE. But the thing is when i tried to create object for the new class named TestClass.cs then its throwing error like "The same table 'Table' cannot be the child table in two nested relations." How to solve this?

Your XML is not valid, you need to remove the lines and make sure to close the node for Table1

<TestClass>
  <TestChildClass>
    <TestName Name="sample">
      <Table Name="table1" IdentityColumnName="RollNo" IntColumn="Mark" CharColumn="Name" >
        <Table Name="table2" IdentityColumnName="RollNo" IntColumn="SubjectCode" CharColumn="Subject" ReferenceColumn ="RollNo" >
            <Table Name="table3" IdentityColumnName="RollNo" IntColumn="Average" CharColumn="Subject" ReferenceColumn ="SubjectCode"/>          
         </Table>
        <Table Name="table4" IdentityColumnName="RollNo" IntColumn="Rank" CharColumn="Name" />
      </Table >
    </TestName >    
  </TestChildClass>
</TestClass>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM