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
The Linq syntax to retrieve the “iffs” could be something like this:
Is It what you’re looking for?