C# check an element exists while using LINQ to XML

前端 未结 6 1027
慢半拍i
慢半拍i 2021-01-02 08:32

OK, bit of a random question, but the best way to do this is to just add the code, you\'ll be able to see what I mean straight away:

XML:



        
6条回答
  •  情书的邮戳
    2021-01-02 08:35

    Have you tried checking if the SuperType element exists before trying to read the value from it?

    ...
    where (c.Element("SuperType") != null && c.Element("SuperType").Value == "1")
    ...
    

提交回复
热议问题