I want to search for the text value of <code>
of Accountants under a job category Accounting.
Below is the idea I am thinking to get this value, but it doesn't work. What is the correct way to access the value of <code>
?
XDocument xml = XDocument.Parse(xmlString);
var accountants = from c in xml.Root.Elements("JobCategory")
where c.Elements("Name").Equals("Accounting")
select c;
var code = from c in accountants.Descendants("Code")
select c;
I am using asp.net MVC. The xmlString
is like this:
<JobCategories xmlns="http://api.trademe.co.nz/v1" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<JobCategory>
<Name>Accounting</Name>
<Code>5001</Code>
<SubCategories>
<JobCategory>
<Name>Accountants</Name>
<Code>5002</Code>
</JobCategory>
<JobCategory>
<Name>Accounts administrators</Name>
<Code>5007</Code>
</JobCategory>
</SubCategories>
</JobCategory>
<JobCategory>
<Name>Agriculture, fishing & forestry</Name>
<Code>5015</Code>
<SubCategories>
<JobCategory>
<Name>Farming</Name>
<Code>5016</Code>
</JobCategory>
<JobCategory>
<Name>Fishing</Name>
<Code>5017</Code>
</JobCategory>
</SubCategories>
</JobCategory>
</JobCategories>