.NET and XML
.NET and XML Contents
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
Partners
Dream.In.Code dotNet Slackers dotNet Spider Your HTML Source VisualBuilder.com DevGuru Planet Source Code ZVON.ORG Web Design ASPAlliance XML Pitstop Scripts
The Spot 4 SAP Bitshop Web Hosting