Note that there are some explanatory texts on larger screens.

plurals
  1. POWHERE IN CLAUSE for LINQ to XML
    primarykey
    data
    text
    <p>The following code should return all barcodes that are in the filter. however it seems to excecute the filter only on the first newrecord. </p> <p>the xml contains 5 newrecords with a barcode subelement ranging 1-5. if the filter contains 1,3 and 4 it returns 1 and if the filter contains 2,3 and 4 it returns a no records.</p> <p>Also the current setup (rpa.XMLData.Elements("NEWFILE").Elements("NEWRECORD") ) returns 5 rows. i have tried seeing what happens if i change this to comeback in a single row (rpa.XMLData.Elements("NEWFILE")) but this does the same in giving me back 1 result being the first hit, ignoring 3 and 4.</p> <p>is there a way to change this LINQ Statement to actually look through all the barcodes?</p> <p>edit: the information comes from a test atm so sorry if it looks a bit weird. i added info on the xml and the filter.</p> <p>also, i have found something extra on the problem if the </p> <p>filter contains 1,2,3 it works. filter contains 1,2,4 it will return 1 and 2 not 4.</p> <p>it seems to be breaking once it can't find a solution.</p> <pre><code>String string2Stream = String.Concat("2", Environment.NewLine, "3", Environment.NewLine, "4", Environment.NewLine, "End"); Stream reader = new MemoryStream(ASCIIEncoding.Default.GetBytes(string2Stream)); StreamReader read = new StreamReader( reader ); var filter = Enumerable.Where(StreamReaderToSeq(read), x =&gt; { int temp; return int.TryParse(x, out temp); }); var query = from p in rpa.XMLData.Elements("NEWFILE").Elements("NEWRECORD") where filter.Contains(p.Element("BAR_CODE").Value) select new { p.Element("BAR_CODE").Value }; </code></pre> <p>Underneath the xml i deleted alot of extra stuff that shouldn't be related.</p> <pre><code>&lt;?xml version=\"1.0\"?&gt; &lt;NEWFILE&gt; &lt;NEWRECORD num=\"1\"&gt;&lt;MAILSORT&gt;&lt;/MAILSORT&gt;&lt;BAR_CODE&gt;1&lt;/BAR_CODE&gt; &lt;/NEWRECORD&gt; &lt;NEWRECORD num=\"2\"&gt;&lt;MAILSORT&gt;&lt;/MAILSORT&gt;&lt;BAR_CODE&gt;2&lt;/BAR_CODE&gt; &lt;/NEWRECORD&gt; &lt;NEWRECORD num=\"3\"&gt;&lt;MAILSORT&gt;&lt;/MAILSORT&gt;&lt;BAR_CODE&gt;3&lt;/BAR_CODE&gt; &lt;/NEWRECORD&gt; &lt;NEWRECORD num=\"4\"&gt;&lt;MAILSORT&gt;&lt;/MAILSORT&gt;&lt;BAR_CODE&gt;4&lt;/BAR_CODE&gt; &lt;/NEWRECORD&gt; &lt;NEWRECORD num=\"5\"&gt;&lt;MAILSORT&gt;&lt;/MAILSORT&gt;&lt;BAR_CODE&gt;5&lt;/BAR_CODE&gt; &lt;/NEWRECORD&gt; &lt;/NEWFILE&gt; </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