attributes - How to find XElement specific Children (in c# with LINQ)? -
i've got xml file :
<root> <environment env="prod"> <key name="big key" propagate="true" value="21" /> </environment> <environment env="pre-prod"> <key name="first key" propagate="true" value="4" /> <key name="second key" propagate="true" value="3" /> </environment> </root>
i want check if key exist in file, , if propagate item true. manage 2 system.xml.linq.xelement : key name="first key" , key name="second key". get 1 pkeyname (like "second key" eg.) can't find how...
public static bool ispropagate(string pxmlfilename, string penvironment, string pkeyname) { var doc = xelement.load(pxmlfilename); ienumerable<xelement> childlist = doc.elements("environment") .where(elt => elt.attribute("env").value == penvironment) .elements(); if (childlist.any()) return true; return false; }
any highly appreciated!
this exact key:
public static bool ispropagate(string pxmlfilename, string penvironment, string pkeyname) { var doc = xelement.load(pxmlfilename); ienumerable<xelement> childlist = doc.elements("environment") .where(elt => elt.attribute("env").value == penvironment) .elements() .where(a => a.attribute("name").value == pkeyname); if (childlist.any()) return true; return false; }
Comments
Post a Comment