Solved

Find the Max ID from an XML file

Posted on 2016-07-25
3
12 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
Comment Utility
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
Comment Utility
Thank you very much.
0
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
Not a problem RadhaKrishnaKiJaya; glad to help.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

9 Experts available now in Live!

Get 1:1 Help Now