Question

I have the following info in an XML file (uploaded here) taken from a RestSharp response, and I only care about the 5 ID elements. I want to get these IDs into an array or list.

enter image description here

How can I extract them?

My attempt so far..

 var root = XElement.Parse(response.Content);
            var number_projects_str = root.FirstAttribute.Value;
            int number_of_projects = -1;

            if (Int32.TryParse(number_projects_str, out number_of_projects))
            {
              //create an array of size number_of_projects
              //... 
            }
Était-ce utile?

La solution

You can use XPathSelectElements() extension method to select first cell from each row (which is the cell that contains ID) :

var Ids = root.XPathSelectElements("/ResultSet/results/rows/row/cell[1]")
              .Select(o => (string)o)
              .ToArray();
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top