title: ColdFusion: do i need to use structKeyExists for every element of a deep struct?
body: <p>Let's say i've just parsed someone else's XML document which is a response to an API request. I want to know if a value nested deep inside exists. If my API request worked, it will be in the same place every time. If my API request fails, the root of the XML is very different.</p>
  
  <p>If I try <code>&lt;cfif structKeyExists(myStruct.level1.level2.level3, 'myTarget')&gt;</code> on a failed api request, I get the fatal error: <code>Element LEVEL1.LEVEL2 is undefined in MYSTRUCT</code>.</p>
  
  <p>Of course, I could try to depend on the root level of the XML telling me of success or failure, and not looking for the result if it failed, but... barring that solution, what should i do?</p>
  
  <p>Do i need to check for the existence of each level of the struct? As in: </p>
  
  <pre><code>&lt;cfif structKeyExists(myStruct, 'level1') 
    and structKeyExists(myStruct.level1, 'level2') 
      and structKeyExists(myStruct.level1.level2, 'level3') 
        and structKeyExists(myStruct.level1.level2.level3, 'myTarget')&gt;
  &lt;!--- ... ---&gt;
  &lt;/cfif&gt;
  </code></pre>
  
  <p>This is not a real-world problem, this is just something i've faced too many times. Please don't tell me solutions that involve changing the API or solutions like those in the third paragraph.</p>
  
  <p>Thanks!</p>
  
  <p>edit: i should have mentioned why i can't use isDefined() - some of the keys do not have syntactically valid names, so isDefined() throws an error, eg myStruct.level1[42].level3</p>