Solved

Find the Max ID from an XML file

Posted on 2016-07-25
3
15 Views
Last Modified: 2016-07-25
Hi Experts,

I have the following xml file. How can I get the max ID from Vb.Net. In this example I should able to get 1 as max id.

<?xml version="1.0" standalone="yes"?>
<XMLDataSet xmlns="http://tempuri.org/XMLDataSet.xsd">
  <Barcodes>
    <ID>0</ID>
    <Barcode>http://www.kaspersky.com/pure</Barcode>
  </Barcodes>
  <Barcodes>
    <ID>1</ID>
    <Barcode>www.rogersparkfoodcoop.com</Barcode>
  </Barcodes>
</XMLDataSet>

Thanks in advance.
0
Comment
Question by:RadhaKrishnaKiJaya
  • 2
3 Comments
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 41728496
Hi RadhaKrishnaKiJaya;

This code snippet will do what you need.
// Defines the namespace used in the XML doc
XNamespace ns = "http://tempuri.org/XMLDataSet.xsd";
// Load the XML document into memory
XDocument xdoc = XDocument.Load("Path and file name to the XML document");
// Get the Max ID 
var maxID = xdoc.Descendants(ns + "ID").Max(x => int.Parse(x.Value));

Open in new window

0
 

Author Closing Comment

by:RadhaKrishnaKiJaya
ID: 41728520
Thank you very much.
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 41728531
Not a problem RadhaKrishnaKiJaya; glad to help.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now