【发布时间】:2011-07-29 08:03:51
【问题描述】:
我是使用 LINQ 的新手。我想使用 LINQ 检索给定字符串的某个值。我有一个包含以下格式的 XML 文档(files.xml)。
<?xml version="1.0" encoding="utf-8" ?>
<DocumentMappings>
<DocumtentCategory>
<CategoryId>001</CategoryId>
<CategoryName>Checksheet and Lists</CategoryName>
<DestinationDocumentLibrary>CheckList and Lists</DestinationDocumentLibrary>
<Multiple>false</Multiple>
</DocumtentCategory>
<DocumtentCategory>
<CategoryId>011</CategoryId>
<CategoryName>Product Information</CategoryName>
<DestinationDocumentLibrary>Product Information</DestinationDocumentLibrary>
<Multiple>true</Multiple>
</DocumtentCategory>
</DocumentMappings>
问题
如何使用 LINQ 检索“DestinationDocumentLibrary”的值作为“Checksheet and Lists”的“CategoryName”的字符串。
在上面的示例中,“检查表和列表”作为参数(字符串)传递,并将动态传递给 LINQ 查询。
希望问题很清楚,并在此先感谢您。
【问题讨论】:
-
所有 3 个都可以正常工作.. 但选择 @Tim 的原因是我在下面的评论中提到的。
标签: c# xml linq linq-to-xml xelement