문제

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.

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top