LINQ to XML 的问题
有一个像这样的 XML 文件:
<Datasets>
<package id="AD">
<iff>LRC_AD_AMSADTEXPDR</iff>
</package>
<package id="AL">
<iff>LRC_AL_CLINICALTCODE</iff>
<iff>LRC_AL_PATALGHISTRY</iff>
<iff>LRC_AL_PATALGYCODE</iff>
<iff>LRC_AL_PATALLERGY</iff>
<iff>LRC_AL_PATALRGYCHEKD</iff>
</package>
<package id="AT">
<iff>LRC_AT_PATALERT</iff>
<iff>LRC_AT_PATALRTCARE</iff>
<iff>LRC_AT_PATALRTCODE</iff>
<iff>LRC_AT_PATALRTDIST</iff>
<iff>LRC_AT_PATALRTHIST</iff>
<iff>LRC_AT_PATALRTSTAT</iff>
</package>
<package id="CDC">
<iff>LRC_CDC_IFMFMCOMMENT</iff>
<iff>LRC_CDC_IFMFORM</iff>
<iff>LRC_CDC_IFMFRMCNTXT</iff>
<iff>LRC_CDC_IFMFRMDATA</iff>
<iff>LRC_CDC_IFMFRMDISDET</iff>
<iff>LRC_CDC_IFMFRMHIMREF</iff>
<iff>LRC_CDC_IFMFRMKEYWRD</iff>
<iff>LRC_CDC_IFMFRMOBSRER</iff>
<iff>LRC_CDC_IFMFRMPLCY</iff>
<iff>LRC_CDC_IFMFRMRCPNT</iff>
<iff>LRC_CDC_IFMFRMREF</iff>
<iff>LRC_CDC_IFMFRMSTAHST</iff>
</package>
</Datasets>
我使用 .NET 3.5 创建一个应用程序,该应用程序将有一个组合框和一个选中列表框控件。 组合框将列出所有包(如 AD、AL、AT 等),选择相应的 iff 元素应绑定到选中列表框。
我成功地使用以下代码绑定了组合框:
var pkgs = from s in xmlDoc.Descendants("package")
where s.HasAttributes && s.Attribute("id") != null &&
!String.IsNullOrEmpty(s.Attribute("id").Value)
select s.Attribute("id").Value;
List<string> lst = pkgs.ToList();
comboBox1.DataSource = lst;
当用户从下拉列表中选择包时,在组合框的 selectedIndexChange 事件中,我想检索该包的相应子元素并将其绑定到选中的列表框。
但是,我无法使用 LINQ 选择所选包的子节点 (iff)。
非常感谢任何帮助!
谢谢
have a XML file like this:
<Datasets>
<package id="AD">
<iff>LRC_AD_AMSADTEXPDR</iff>
</package>
<package id="AL">
<iff>LRC_AL_CLINICALTCODE</iff>
<iff>LRC_AL_PATALGHISTRY</iff>
<iff>LRC_AL_PATALGYCODE</iff>
<iff>LRC_AL_PATALLERGY</iff>
<iff>LRC_AL_PATALRGYCHEKD</iff>
</package>
<package id="AT">
<iff>LRC_AT_PATALERT</iff>
<iff>LRC_AT_PATALRTCARE</iff>
<iff>LRC_AT_PATALRTCODE</iff>
<iff>LRC_AT_PATALRTDIST</iff>
<iff>LRC_AT_PATALRTHIST</iff>
<iff>LRC_AT_PATALRTSTAT</iff>
</package>
<package id="CDC">
<iff>LRC_CDC_IFMFMCOMMENT</iff>
<iff>LRC_CDC_IFMFORM</iff>
<iff>LRC_CDC_IFMFRMCNTXT</iff>
<iff>LRC_CDC_IFMFRMDATA</iff>
<iff>LRC_CDC_IFMFRMDISDET</iff>
<iff>LRC_CDC_IFMFRMHIMREF</iff>
<iff>LRC_CDC_IFMFRMKEYWRD</iff>
<iff>LRC_CDC_IFMFRMOBSRER</iff>
<iff>LRC_CDC_IFMFRMPLCY</iff>
<iff>LRC_CDC_IFMFRMRCPNT</iff>
<iff>LRC_CDC_IFMFRMREF</iff>
<iff>LRC_CDC_IFMFRMSTAHST</iff>
</package>
</Datasets>
I use .NET 3.5 to create an app which will have a combobox and a checkedlistbox control.
The combobox will list down all packages (like AD, AL, AT, etc.) upon selecting which the corresponding iff elements should be bound to the checkedlistbox.
I was successful in binding combobox with following code:
var pkgs = from s in xmlDoc.Descendants("package")
where s.HasAttributes && s.Attribute("id") != null &&
!String.IsNullOrEmpty(s.Attribute("id").Value)
select s.Attribute("id").Value;
List<string> lst = pkgs.ToList();
comboBox1.DataSource = lst;
When user selects the package from dropdown, in selectedIndexChange event of combobox, I want to retieve the corresponding child elements of that package and bind it to checked list box.
However, I am unable to select the child nodes (iffs) of the selected package using LINQ.
Any help is greatly appreciated!
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检索“iff”的 Linq 语法可能是这样的:
Is It what you're要找的?
The Linq syntax to retrieve the "iffs" could be something like this:
Is It what you're looking for?