Question

I am not trying to save dataset or datatable to a xml file rather create a xml structure for saving related data? For example i would like to know how below data could be in a xml file

User

UserId
Username
Password

Roles

RoleId
UserId [FK]
CreatedOn

will it look like this

<User userid="" username="" password="">
<Roles id="">
 <Name></Name>
 <Description></Description>
</Roles>
</User>

which structure would be best to use xml files as DB

Était-ce utile?

La solution

I think you want to consider implementing the XML in a more normalized manner, similar to how you would do so with a relational database. For instance in your current solution you would be required to type out the entire role structure within every user such as

<User userid="1" username="user01" password="password">
   <Roles id="1">
      <Name>Role 1</Name>
      <Description>This is Role 1</Description>
   </Roles>
</User>
<User userid="2" username="user02" password="password">
   <Roles id="1">
      <Name>Role 1</Name>
      <Description>This is Role 1</Description>
   </Roles>
</User>

A normalized structure could look like the following

<Roles>
   <Role id="1">
      <Name>Role 1</Name>
      <Description>This is Role 1</Description>
   </Role>
</Roles>

<User id="1" username="user01" password="password">
   <Roles>
      <Role>1</Role>
   </Roles>
</User>
<User id="2" username="user02" password="password">
   <Roles>
      <Role>1</Role>
   </Roles>
</User>

Hope this helps

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top