Question

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.

Was it helpful?

Solution

Quick answer is no. You have to check for a null reference before invoking methods or operators upon members.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top