c# - Select XElements from comma separated values -
i using linq-to-xml in project , want extract elements in comma separated string i.e.
here sample xml file
<?xml version="1.0" encoding="utf-8"?> <newdataset> <table> <entity>employee</entity> <entityid>2857</entityid> .. more nodes... .. more nodes... </table> <table> <entity>employee</entity> <entityid>2856</entityid> .. more nodes... .. more nodes... </table> ....... </newdataset> here xelement:
xelement mainentities = xelement.load(strfilename); ienumerable<xelement> entityelements; entityelements = mainentities.elements("table").where(xtab => (string)xtab.element("entity").value == "employee"); and comma separated string
var filter = new list<string> { stremployeeids }; i tried
entityelements = mainentities.elements("table").where(xtab => (string)xtab.element("entity").value == "employee" && filter.contains((string)xtab.element("entityid").value)); but it's not working...
how can got elements in filter entityelements;
assuming stremployeeids defined this:
string stremployeeids = "1,2,3"; you need split string create list out of it:
string[] filter = stremployeeids.split(','); c# xml linq
No comments:
Post a Comment