Solved

Find the Max ID from an XML file

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

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 63

Expert Comment

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

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

821 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