c# - Where condition in XDocument linq query -


i have code like:

jobdetails.group = tm_item.group_xml.tostring(); //xml var xdoc = xdocument.parse(jobdetails.group); var data = xdoc.root.elements().orderby(x => (string)x.attribute("name")); 

xml:

<groups>       <group name="front0">         <room_type>front</room_type>         <dimension>not available</dimension>         <status>pending</status>         <notes>none</notes>         <user>r2g</user>         <audio_length>00:00:00</audio_length>         <image_count>1</image_count>         <section_count>0</section_count>       </group> </groups> 

i want put condition in xdoc.root.elements(),

i tried xdoc.root.elements().orderby(x => (string)x.attribute("name")).where(x => (string)x.attribute("user").value == loggedin_user); doesnot give me output..i getting object reference not set instance of object. suggestion?

you accessing attribute("user") of attribute("name"), accessing user's property value. 1 of these null.

try construct query looks elements attribute name missing, or such return element user attribute missing. suppose find guilty element.

then reformat query protect, e.g. adding where(at => @ != null) before accessing properties.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -