开发者

How to generate the unique id dynamically for one of the xml node while inserting data into the XML file?

I am developing window phone 7 application. I am using XML as a database for my application. I am using a XML file instead of a database table for my application. I having the following structure for one of my xml file.

<?xml version="1.0" encoding="utf-8" ?>
<Categories>
  <Category>
    <Category_ID></Category_ID>
    <Category_Name></Category_Name>
    <TransactionType_ID></TransactionType_ID>
  </Category>
  <Category>
    <Category_ID></Category_ID>
    <Category_Name></Category_Name>
    <TransactionType_ID></TransactionType_ID>
  </Category>
</Categori开发者_运维技巧es>

In the above XML file I am inserting the values for Category_Name & TransactionType_ID through the user interface of my mobile application by using LINQ to XML. In the above XML file I am treating the Category_ID as a primary key & TransactionType_ID as a foreign key which belongs to other xml file. In the above XML file I want to generate the autoincrement id for the node Category_ID as we do in the database table. How to generate the autoincrement id for the node Category_ID ? Can you please provide me any code, solution or link through which I can solve the above issue? If anyone is having any other ideas then please share. If I am doing anything wrong then please guide me.


you can use Guid for example

var uniqueIdentifier = Guid.NewGuid();//Will be generate unique value


You can use use a GUID (like Serghei suggested) or you can use an integer. The Guid.NewGuid() method will return a new global unique id for each call. If u want to use a int value instead you can save the highest id you already used in the application setting: In the applicatins settings create a ArticlIdMax property of the type int. then you can get a new id with this code:

int newID = Test.Properties.Settings.Default.ArtcilIdMax++;
Test.Properties.Settings.Default.Save();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜