Hi. I've got to write some code to get data from an XML document and turn it into C# objects. Problem is that the XML document will not always have the same nodes, since it is produced from a web form that people have filled in varying amounts of (which I cannot control since the xml is from a 3rd party resource). For example sometimes the XML document has a <NamePrefix> tag to contain Mr./Mrs./... etc, but if people haven't filled this in on the form it won't. This means that when I call
document.selectSingleNode("NamePrefix");
this will sometimes throw an exception if the <NamePrefix> tag does not exist. The obvious way around this is to write a try-catch block around every such statement in my code, but this would mean about 100 try-catch blocks, which I'm sure would be terrible for performance, let alone readability! Is there another way to solve this problem?
Many thanks.