Domanda

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
              //... 
            }
È stato utile?

Soluzione

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();
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top