?
Solved

sorting XML

Posted on 2013-11-15
4
Medium Priority
?
268 Views
Last Modified: 2013-11-30
Hi,

I would like to read the simple XML below.
<list version="1.0">
<meta>
  <type>resource-list</type>
</meta>
<resources start="0" count="4">
  <resource classname="Quote">
    <field name="name">Vincent</field>
    <field name="username">Hill</field>
    <field name="age">0.32</field>
    <field name="hair">black</field>
  </resource>
  <resource classname="Quote">
    <field name="name">John</field>
    <field name="username">Tedelon</field>
    <field name="age">27</field>
    <field name="hair">brown</field>
  </resource>
  <resource classname="Quote">
    <field name="name">Michael</field>
    <field name="username">Lopez</field>
    <field name="age">20</field>
    <field name="hair">red</field>
  </resource>
  <resource classname="Quote">
    <field name="name">Frank</field>
    <field name="username">Lopez</field>
    <field name="age">25</field>
    <field name="hair">black</field>
  </resource>
</resources>
</list>

Open in new window


 and be able to find the record and the corresponding name with the max age.

How best can it be done with the minimum lines of code?

thanks!
0
Comment
Question by:Mydeen Yussouf
[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
4 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39653356
One possible approach would be load the XML into a System.Data.DataSet, and then use a filter to find the record that you need.
0
 
LVL 1

Author Comment

by:Mydeen Yussouf
ID: 39653416
Thanks @TheLearnedOne, can you show me the code to do that for the above XML?
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 39653455
The appropriate method depends on where you are getting the XML.

Here is an example:

Loading a DataSet from XML
http://msdn.microsoft.com/en-us/library/fx29c3yd(v=vs.110).aspx

DataSet dataSet = new DataSet();
DataTable dataTable = new DataTable("table1");
dataTable.Columns.Add("col1", typeof(string));
dataSet.Tables.Add(dataTable);

string xmlData = "<XmlDS><table1><col1>Value1</col1></table1><table1><col1>Value2</col1></table1></XmlDS>";

System.IO.StringReader xmlSR = new System.IO.StringReader(xmlData);

dataSet.ReadXml(xmlSR, XmlReadMode.IgnoreSchema);

Open in new window


Then you can use the DataSet visualizer to see the structure that is inferred from the XML.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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 …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses

777 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