How to retrieve the node elements based on the name given in linq from XML file
My sample xml:
<Documents>
<Doc>
<Name>CSC Customer</Name>
<Path>~/Downloads/DocumentTemplates/ACCT_CSC_Customer NSF Check Letter Template.htm</Path>
</Doc>
<Doc>
<Name>VPS Violation NSF</Name>
<Path>~/Downloads/DocumentTemplates/ACCT_VPS_Violation NSF Check Letter Template.htm</Path>
</Doc>
</Documents>
This is the sample xml file and i want to get the path based on the node "Name" given.
for example if i give "CSC Cusotmer" i开发者_如何学Python have to get the corresponding path. i want the solution through the Linq.
How do i get the values ( path ) from the xml file using linq
Assuming your XML is in a file called "data.xml" this should work:
var root = XElement.Load(@"data.xml");
var path = (from e in root.Elements("Doc")
where e.Element("Name").Value == "CSC Customer"
select e.Element("Path").Value).FirstOrDefault();
精彩评论