-
Notifications
You must be signed in to change notification settings - Fork 1
/
Folders.cs
29 lines (26 loc) · 898 Bytes
/
Folders.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
public class Folders
{
public static IEnumerable<string> FolderNames(string xml, char startingLetter)
{
return XDocument.Parse(xml).Descendants()
.Where(x => x.Attribute("name").Value.StartsWith(Char.ToString(startingLetter)))
.Select(x => x.Attribute("name").Value);
}
public static void Main(string[] args)
{
string xml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<folder name=\"c\">" +
"<folder name=\"program files\">" +
"<folder name=\"uninstall information\" />" +
"</folder>" +
"<folder name=\"users\" />" +
"</folder>";
foreach (string name in Folders.FolderNames(xml, 'u'))
Console.WriteLine(name);
}
}