Ignore the value of an empty Attributes in the element LINQ C#

giannasha

New Member
I'm trying to retrieve values from an XML file and I find some values are empty. \[code\]textBox6, textBox7, textBox14\[/code\] corresponding element attribute values are empty/null. The error message is \[code\]Null reference error was unhanded\[/code\] . How can fix this??\[code\]private void DisplayFile(string path) { var doc = XDocument.Load(path); var ns = doc.Root.GetDefaultNamespace(); var conn = doc.Root.Element(ns + "connection"); textBox1.Text = conn.Element(ns + "sourceId").Value; var doc1 = XDocument.Load(path); var ns1 = doc.Root.GetDefaultNamespace(); var conn1 = doc.Root.Element(ns1 + "connectionContext"); }\[/code\]
 
Back
Top