 <p>I have figured it out! Although I don't know why the Xlinq approach doesn't work... here is the code that worked for me instead of the query:</p> <pre><code> public XElement filter(int min = 0, int max = int.MaxValue) { XElement filtered = new XElement("Stock"); foreach (XElement product in xmlFile.Elements("Product")) { if ((int)product.Element("Price") &gt;= min &amp;&amp; (int)product.Element("Price") &lt;= max) filtered.Add(product); } return filtered; } </code></pre> <p>that would be great if someone gives me an explain. thanks for reading</p>