Tanya
Tanya

Reputation: 1621

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?

Upvotes: 0

Views: 697

Answers (1)

Matt Smucker
Matt Smucker

Reputation: 5244

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>

Upvotes: 1

Related Questions