Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var xml =
@"<?xml version=""1.0"" encoding=""UTF-8""?>
<report name=""ReportName"">
<agency name=""agency1"">
<office name=""office1""></office>
<office name=""office2""></office>
<office name=""office3""></office>
</agency>
<agency name=""agency2"">
<office name=""office1"">
<agent name=""agent Amy""></agent>
<address name=""address line""></address>
</office>
<office name=""office2""></office>
<office name=""office3""></office>
</agency>
<agency name=""agency3"">
<office name=""office1"">
<agent name=""agent Bettie"">
<subagent name=""sub-agent bob"">
<phone name=""456-789-1230""></phone>
</subagent>
<subagent name=""sub-agent billy""></subagent>
</agent>
<address name=""address line"">
<faxnumber name=""1234567890""></faxnumber>
</address>
</office>
<office name=""office2""></office>
<office name=""office3""></office>
</agency>
</report>";
var names =
XDocument
.Parse(xml)
.Root
.Descendants()
.Select(x => x.Attribute("name").Value)
.Dump();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.