Update - I just realised that the tags have changed to vb.net
but the framework classes are the same so I hope it remains useful.
You could use XDocument
//assuming that xml contains the string result XML:
void Main()
{
var xml = GoGetSomeXML();//your sp call here, etc.
var xd = XDocument.Parse(xml);
foreach (var row in xd.Descendants().Where(x=>x.Name.LocalName=="row"))
{
var DocType = GetSubElementValue(row,"DocType");
var GeneralName = GetSubElementValue(row,"GeneralName");
var StartDate = GetSubElementValue(row,"StartDate");
var EndDate = GetSubElementValue(row,"EndDate");
var CertNo = GetSubElementValue(row,"CertNo");
Console.WriteLine("{0} {1} {2} {3} {4}",DocType,GeneralName,StartDate,EndDate,CertNo);
}
}
object GetSubElementValue(XElement container, string subElementName)
{
var subElement = container.Descendants().FirstOrDefault(d=>d.Name.LocalName==subElementName);
if (subElement==null) return null;
return subElement.Value;
}
produces
1 CV 1900-12-31 1900-12-31
Also if your result set is likely to not change and you can control fully the data types, etc, you might also consider using XmlSerializer and define a class that represents the various elements in your result set:
void Main()
{
var xd = XDocument.Parse(xml);
var ser =new XmlSerializer(typeof(row));
foreach (var rowElement in xd.Descendants().Where(x=>x.Name.LocalName=="row"))
{
using (var reader = rowElement.CreateReader())
{
var row1 = ser.Deserialize(reader) as row;
Console.WriteLine(row1);
}
}
}
public class row
{
public int DocType {get;set;}
public string GeneralName{get;set;}
public DateTime StartDate{get;set;}
public DateTime EndDate{get;set;}
public string CertNo{get;set;}
}
Note that you can use various attributes to control how the XML maps to the ClassName and Properties, so this is a very very basic example - the class name does not have to be "row" when you use the XmlRootAttribute
class and so on...
The Serialiser route is probably the most efficient for large amounts of data, although for 300 rows I am not sure you will see much difference.