Slinnalaype
New Member
I'm writing a function that loads and XML document and converts it to a CSV. Since I need only some values from the XML file, the goal i'm trying to achieve is to select only the nodes I'm interested in.Here's my code:\[code\] XDocument csvDocument = XDocument.Load(tempOutput); StringBuilder csvBuilder = new StringBuilder(1000); foreach (XElement node in csvDocument.Descendants("Sample")) { foreach (XElement innerNode in node.Elements()) { csvBuilder.AppendFormat("{0},", innerNode.Value); } csvBuilder.Remove(csvBuilder.Length -1, 1); csvBuilder.AppendLine(); } csvOut = csvBuilder.ToString();\[/code\]But, in this way I'm selectin ALL the child nodes inside the "Sample" node.In the XML, "Sample" tree is:\[code\]<Sample Type="Object" Class ="Sample"> <ID>1</ID> <Name>10096</Name> <Type>2</Type> <Rep>0</Rep> <Selected>True</Selected> <Position>1</Position> <Pattern>0</Pattern> </Sample>\[/code\]Code works flawlessly, but I need only "ID" and "Selected" to be selected and their values written inside the CSV file.Could anyone point me in the right direction, please?Thanks.