Query IEnumerable<XObject> containing unknown elements

Scenebb

New Member
I am looking to query an IEnumerable to filter it based on attributes held in the lower elements. I don't know the element names but do know the attributes to query.To give more details.This SearchVars class will contain selected search options on a form. It also contains a property for ObjectType which is the identifier for which XML objects are in the file. for the below XML example Object Type would be T1\[code\] class SearchVars { public string ObjectType { get; set; } public string ClientId { get; set; } public string CustRef { get; set; } }\[/code\]An Example XML Extract\[code\]<root><T1> <FT ClientID="PCL1" /> <T2 CustRef="Cust1"> <T3 Name="Site1"> <TER Error="123" ErrorText="Error 123" /> <TER Error="234" ErrorText="Error 234" /> <T4 SubErr="50420208"> <TSER ID="2199991741074" CHN="1"> <TER Error="567" ErrorText="Error 567" /> </TSER> </T4> </T3> </T2></T1><T1> <FT ClientID="PCL1" /> <T2 CustRef="Cust2"> <T3 Name="Site2"> <TER Error="123" ErrorText="Error 123" /> <TER Error="234" ErrorText="Error 234" /> </T3> </T2></T1></root>\[/code\]I would be trying to search for Error attributes based on ClientID's and CustRef's. In the search method my initial code is to pull all the T1's into an enumerable. the 2 empty IFs is where I will have LINQ queries filtering the data on the search variable. So if ClientID is PCL1, filter the T1s where that client ID attribute value is present.\[code\] public static IEnumerable<XObject> PerformSearch(string xmlData, Models.SearchVars vars) { XDocument document = XDocument.Parse(xmlData); IEnumerable<XObject> result = document.Descendants(vars.ObjectType); if (! string.IsNullOrEmpty(vars.ClientId)) { } if (!string.IsNullOrEmpty(vars.CustRef)) { } return result; }\[/code\]I hope what I am attempting is clear and looking forward to learning a little today. Thanks
 
Top