mt600
asked on
Retrieving optional nodes from an XmlDocument
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.
For example
<name><firstname>a</firstn ame><surna me>b</surn ame></name >
or
<name><firstname>a</firstn ame><surna me>c</surn ame><middl ename>b</m iddlename> </name>
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.
Cheers
For example
<name><firstname>a</firstn
or
<name><firstname>a</firstn
How can i retrieve these single nodes quickly from Xml using c#?
I have been using .SelectSingleNode("//name/
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.
Cheers
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER