Note that there are some explanatory texts on larger screens.

plurals
  1. POTroubles searching xml document with LINQ
    primarykey
    data
    text
    <p>I have an xml document that has 3 elements in this format:</p> <pre><code>&lt;Codes&gt; &lt;Code&gt; &lt;CodeScenario&gt;3&lt;/CodeScenario&gt; &lt;CodeScenario&gt;4&lt;/CodeScenario&gt; &lt;CodeScenario&gt;6&lt;/CodeScenario&gt; &lt;CodeScenario&gt;7&lt;/CodeScenario&gt; &lt;CodeCategory&gt;Category3&lt;/CodeCategory&gt; &lt;CodeID&gt;043&lt;/CodeID&gt; &lt;CodeDescription&gt;Description3&lt;/CodeDescription&gt; &lt;CodeType&gt;PE&lt;/CodeType&gt; &lt;/Code&gt; &lt;Code&gt; &lt;CodeCategory&gt;Category2&lt;/CodeCategory&gt; &lt;CodeID&gt;046&lt;/CodeID&gt; &lt;CodeDescription&gt;Description2&lt;/CodeDescription&gt; &lt;CodeType&gt;PE&lt;/CodeType&gt; &lt;/Code&gt; &lt;Code&gt; &lt;CodeScenario&gt;2&lt;/CodeScenario&gt; &lt;CodeCategory&gt;Category1&lt;/CodeCategory&gt; &lt;CodeID&gt;100&lt;/CodeID&gt; &lt;CodeDescription&gt;Description1&lt;/CodeDescription&gt; &lt;CodeType&gt;PR&lt;/CodeType&gt; &lt;/Code&gt; &lt;/Codes&gt; </code></pre> <p>I'd like to be able to use a linq query to tell me if a code element has a codetype based on ID. This is what I've come up with so far. It works but it's ugly and I'd prefer to use dot notation if possible. Can anybody help me out?</p> <pre><code>public bool HasCodeType(string CodeType, string Code) { var QueryResult = (from descendant in XMLdocument.Descendants("Code") from type in descendant.Elements("CodeType") where type != null &amp;&amp; type.Value.Equals(CodeType) select new { CID = descendant.Element("CodeID").Value }).Distinct(); foreach (var result in QueryResult) { if (Code == result.CID) return true; } return false; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload