Thursday, 19 September 2013

C# XMl Deserialisation with non existing Paths

C# XMl Deserialisation with non existing Paths

I've with xsd.exe created the class for my XML. In the XML (SEPA camt.053)
are multiply nested Nodes that have minOccurs = 0.
I navigate to the node like this:
entry.NtryDtls[0].TxDtls[0].RltdPties.CdtrAcct.Id.Item
In this Path RltdPties, CdtrAcct and Id could be null.
If RltdPties is null I get an Exception, because CdtrAcct doesn't exist.
Is there an easy way without checking each node if it is null to get the
Value of Item? If path doesn't exist it would be enough to get null (or
something else) from the last node that I can check.
My idea is to surround this query with try/catch and if it throws an
Exception I can set the Variable to an empty string or so.
Thanks in advanced

No comments:

Post a Comment