c# - linq to xml, handling empty tags -


the following link statement works fine if source xml contains number or if tags missing. problem have when tags empty or if non-numeric value used. can statement modified handle these situations ?

convert.toint32((string)data.elements("groupby").elements("depth").firstordefault() ?? "0") 

don't know of way solve linq if cannot guarantee content of xml document easier use int.tryparse()?, e.g.

int result = 0; int.tryparse((string)data.elements("groupby").elements("depth").firstordefault(), out result); 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -