Note that there are some explanatory texts on larger screens.

plurals
  1. POLinq to Object/XML where element doesn't exist
    primarykey
    data
    text
    <pre><code>var doc3 = XDocument.Load(@"C:\Projects\ScanBandConfigTesting\ScanBandConfigTesting\ScanBandConfigSmall.xml"); var scanBand = new ScanBand() { ListOfForms = (from form in doc3.Descendants("form") select new ScanBandForm() { FormTypes = form.Attribute("types").Value, ScanBandNumber = form.Attribute("number").Value, ListOfRows = (from row in form.Descendants("row") select new ScanBandRow() { AllowSpaces = row.Element("allowSpaces").Value.ToLower() == "true", SplitCharacter = row.Element("splitCharacter").Value, ListOfColumns = (from column in row.Descendants("column") select new ScanBandColumn() { AlwaysKey = column.Element("allwaysKey").IsEmpty ? false : column.Element("allwaysKey").Value.ToLower() == "true", DataTypeString = column.Element("dataType").IsEmpty ? string.Empty : column.Element("dataType").Value, MatchingFieldName = column.Element("matchingFieldName").IsEmpty ? string.Empty : column.Element("matchingFieldName").Value, NonField = column.Element("nonField").IsEmpty ? false : column.Element("nonField").Value.ToLower() == "true", RegularExpressionString = column.Element("regularExpression").IsEmpty ? string.Empty : column.Element("regularExpression").Value, }).ToList() }).ToList() }).ToList() }; </code></pre> <p>XML</p> <pre><code>&lt;scanBand&gt; &lt;form types="FormName" number="1"&gt; &lt;row&gt; &lt;allowSpaces&gt;false&lt;/allowSpaces&gt; &lt;splitCharacter&gt;&amp;#32;&lt;/splitCharacter&gt; &lt;column&gt; &lt;matchingFieldName&gt;FirstField&lt;/matchingFieldName&gt; &lt;dataType&gt;CB&lt;/dataType&gt; &lt;regularExpression&gt;&lt;/regularExpression&gt; &lt;allwaysKey&gt;false&lt;/allwaysKey&gt; &lt;nonField&gt;false&lt;/nonField&gt; &lt;/column&gt; &lt;column&gt; &lt;matchingFieldName&gt;SecondField&lt;/matchingFieldName&gt; &lt;dataType&gt;CB&lt;/dataType&gt; &lt;regularExpression&gt;&lt;/regularExpression&gt; &lt;allwaysKey&gt;false&lt;/allwaysKey&gt; &lt;nonField&gt;false&lt;/nonField&gt; &lt;/column&gt; &lt;column&gt; &lt;matchingFieldName&gt;ThirdField&lt;/matchingFieldName&gt; &lt;dataType&gt;CB&lt;/dataType&gt; &lt;regularExpression&gt;&lt;/regularExpression&gt; &lt;!--&lt;allwaysKey&gt;&lt;/allwaysKey&gt;--&gt; &lt;nonField&gt;true&lt;/nonField&gt; &lt;/column&gt; &lt;/row&gt; &lt;/form&gt; &lt;/scanBand&gt; </code></pre> <p>Goal is to have this not blow up when one of the elements in the .xml file don't exist. I tried to play around with .Any() but haven't been successful.</p> <p>I would rather not iterate through using foreach and would rather stick w/ LINQ</p> <p>Any help is much appreciated</p>
    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.
    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