BizTalk Utilities CV ,   Jobs ,   Code library
 
Home Page


Add/Edit your code items
Search the code library
Browse for the code library


.NET and XML
How to read Nodes with XmlNodeReader?
How to Get the Attribute Value with XmlNodeReader and GetAttribute?
How to skip child nodes with XmlNodeReader and Skip?
How to convert the return value from XML with XmlConvert and ToInt32?
What is the 'pull model'?
What is EXSLT.NET?
What is ADO.NET?
How to create a ""hello world"" XML WebService in Visual Studio .NET?
Accessing and Manipulating XML Data in Microsoft .NET Framework
Developing Multi-Threaded .NET Applications


 
 

<< XSLT 


By Sonu Kapoor
First Posted 02/20/2005
Times viewed 188

How to auto-increment an unique ID in XML with XmlTextReader?


Summary How to auto-increment an unique ID in XML with XmlTextReader?

If you have worked with databases then you know that you can assign some fields to use auto increment values. They can be very useful, if you want to edit an item. All you will need is the ID of the item. In an XML file you can also create such a auto increment element. However you will need to increment manually with a self-defined function. In this example you will see how you can create such a function.

One important thing that you should know is that, when ever you increment the ID, its better to lock the file prior doing that. The reason for locking the XML file is that if somebody else uses the function you will have duplicated ID's.

I am using the following XML for the example. As you can see each person contains an ID. The highest person ID is 15 so the function should return 16 as the next ID.

Output:

16

Additional information

Further additional information


Rate this article on a scale of 1 to 10 (0 votes, average 0)

Your vote :  

<< XSLT 





Leave a comment for this article
Your name
Your email (optional)
Your comment
Optional: Upload an attachment
Enter the code shown:

 
 

    Email TopXML