Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Find the Max ID from an XML file

Posted on 2016-07-25
3
Medium Priority
?
36 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 2000 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 64

Expert Comment

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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
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…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

618 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