Solved

Find the Max ID from an XML file

Posted on 2016-07-25
3
17 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

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.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

813 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

10 Experts available now in Live!

Get 1:1 Help Now