Next node in xml with same element name

I've been working on this problem for a few hours now and I have searched all around with no luck for a solution :(

What I am trying to do is print out names of the nodes, what i have is the amount of nodes that exist so I know how many times to loop but am having the hardest of times retrieving the values

What I have tried:

int num = Convert.ToInt32(queuecount);
var jobs = QueueXML.SelectSingleNode(xpathjobsfilename).InnerText;
PreviousQueue = jobs.ToString();

//foreach(loop < num)
//{
//    if (CurrentQueue == PreviousQueue)
//    {

//    }
//    else
//    {
//        resultsListView.Items.Clear();
//        resultsListView.Items.Add(jobs[num]);
//    }
//    loop++;
//}

foreach (char JobName in jobs.ToString())
{
    if (CurrentQueue == PreviousQueue)
    {
    }
    else
    {
        resultsListView.Items.Clear();
        resultsListView.Items.Add(jobs[num]);
    }
}  

Edit: Example XML

 <jobs>
    <job>
      <timeleft>0:00:00</timeleft>
      <mb>1419.60536003</mb>
      <msgid></msgid>
      <filename>Extended_Final</filename>
      <mbleft>1274.33209419</mbleft>
      <id>nzo_i7qxxq</id>
    </job>
    <job>
      <timeleft>0:00:00</timeleft>
      <mb>9.22459220886</mb>
      <msgid></msgid>
      <filename>Video2</filename>
      <mbleft>9.22459220886</mbleft>
      <id>2m3dv5</id>
    </job>
  </jobs>

I want to retrieve the job details for each individual jobs

Answers


Use LINQ2XML.Its COOL

XElement doc=XElement.Load("yourXMLfile.xml");

string timeleft,mb,msgid,filename,mbleft,id;

foreach(XElement elm in doc.Descendants().Elements("job"))
{

timeleft=elm.Element("timeleft").Value;//time left value
mb=elm.Element("mb").Value;//mb value
msgid=elm.Element("msgid").Value;//msgid value
filename=elm.Element("filename").Value;//filename value
mbleft=elm.Element("mbleft").Value;//mbleft value
id=elm.Element("id").Value;//id value

}

Use this code to loop through your job-nodes.

XmlDocument doc = new Windows.Data.Xml.Dom.XmlDocument();
doc.Load(@"/path/to/xml/file");

foreach (XmlNode job in doc.SelectNodes("/jobs/job"))
{
    string filename = job.SelectSingleNode("filename").InnerText;
    double mbleft = double.Parse(job.SelectSingleNode("mbleft").InnerText);
}

I am not quite sure what you want to do with it. If you want to use that information throughout your program, I'd create a job datatype and parse the XML document to a List<Job>. In any case the above code will enable you to access the information you are after.


Need Your Help

Javascript regular expression alternation

javascript regex

I'm creating a javascript regex to match queries in a search engine string. I am having a problem with alternation. I have the following regex:

How to verify existence of a table with a given ID in a word doc in C# VSTO 3

c# ms-word vsto iqueryable officedev

I want to check for the existence of a table with a given ID in a word document in C# (VS 2008) Visual Studio Tools for Office (version 3).