Retrieving optional nodes from an XmlDocument
Posted on 2004-10-27
I have some Xml documents which i want to parse into C#, but they have many optional nodes that may or may not be there.
How can i retrieve these single nodes quickly from Xml using c#?
I have been using .SelectSingleNode("//name/firstname") etc but these throw an exception if the node is not there. Exceptions are pretty computationally expensive so i want to find a better way of finding out if a node exists in an xml document.
In summary, if i have an xml document which has lots of optional nodes, what is the best way to program my C# to use the values in these nodes if they exist.