title: Nest within a Nest: XML Mapping
body: <p>I am trying to reverse engineer the below XML extract in a mapping document using XPaths. The below data will be coming from a SAS dataset.</p>
  
  <pre><code>            &lt;data1:Animal&gt;
                  &lt;data1:AnimalDetails&gt;
                      &lt;data1:Name&gt;Abcd&lt;/data1:Name&gt;                       
                  &lt;/data1:AnimalDetails&gt;
                  &lt;data1:AnimalCondition&gt;
                          &lt;data1:ConditionType&gt;YYY&lt;/data1:ConditionType&gt;
                          &lt;data1:SignsDescription&gt;XXX&lt;/data1:SignsDescription&gt;
                  &lt;/data1:AnimalCondition&gt;
              &lt;/data1:Animal&gt;
              &lt;data1:Parties&gt;
                  &lt;data1:PolicyHolder&gt;
                  &lt;data1:Type&gt;PolicyHolder&lt;/data1:Type&gt;
                      &lt;data1:Person&gt;
                          &lt;data1:Title&gt;Mrs&lt;/data1:Title&gt;
                      &lt;/data1:Person&gt;
                  &lt;/data1:PolicyHolder&gt;
              &lt;/data1:Parties&gt;
  </code></pre>
  
  <p>I know it involves creating a nest within a nest. I am using the below code to get the PolicyHolder tag but not sure how to do the Person tag within the PolicyHolder Tag.</p>
  
  <pre><code>&lt;COLUMN name="PETNAME"&gt;
  &lt;PATH syntax="XPath"&gt;/REQUEST/DATA/ANIMAL/ANIMALDETAILS/Name&lt;/PATH&gt;
  &lt;TYPE&gt;character&lt;/TYPE&gt;
  &lt;DATATYPE&gt;string&lt;/DATATYPE&gt;
  &lt;LENGTH&gt;30&lt;/LENGTH&gt;
  &lt;/COLUMN&gt;
  
   &lt;COLUMN name="condit_type"&gt;
  &lt;PATH syntax="XPath"&gt;/REQUEST/DATA/ANIMAL/ANIMALCONDITION/ConditionType&lt;/PATH&gt;
  &lt;TYPE&gt;character&lt;/TYPE&gt;
  &lt;DATATYPE&gt;string&lt;/DATATYPE&gt;
  &lt;LENGTH&gt;17&lt;/LENGTH&gt;
  &lt;/COLUMN&gt;
  
  &lt;COLUMN name="signs"&gt;
  &lt;PATH syntax="XPath"&gt;/REQUEST/DATA/ANIMAL/ANIMALCONDITION/SignsDescription&lt;/PATH&gt;
  &lt;TYPE&gt;character&lt;/TYPE&gt;
  &lt;DATATYPE&gt;string&lt;/DATATYPE&gt;
  &lt;LENGTH&gt;40&lt;/LENGTH&gt;
  &lt;/COLUMN&gt;
  
  
  &lt;COLUMN name="party_type"&gt;
  &lt;PATH syntax="XPath"&gt;/REQUEST/DATA/PARTIES/POLICYHOLDER/Type&lt;/PATH&gt;
  &lt;TYPE&gt;character&lt;/TYPE&gt;
  &lt;DATATYPE&gt;string&lt;/DATATYPE&gt;
  &lt;LENGTH&gt;13&lt;/LENGTH&gt;
  &lt;/COLUMN&gt;
  
  &lt;COLUMN name="TITLE"&gt;
  &lt;PATH syntax="XPath"&gt;/REQUEST/DATA/PARTIES/POLICYHOLDER/PERSON/Title&lt;/PATH&gt;
  &lt;TYPE&gt;character&lt;/TYPE&gt;
  &lt;DATATYPE&gt;string&lt;/DATATYPE&gt;
  &lt;LENGTH&gt;5&lt;/LENGTH&gt;
  &lt;/COLUMN&gt;
  </code></pre>
  
  <p>This is the output I am getting:</p>
  
  <pre><code>&lt;ANIMAL&gt;
  &lt;ANIMALDETAILS&gt;
  &lt;Name&gt;Abcd&lt;/Name&gt;
  &lt;/ANIMALDETAILS&gt;
  &lt;ANIMALCONDITION&gt;
  &lt;ConditionType&gt;YYY&lt;/ConditionType&gt;
  &lt;SignsDescription&gt;XXX&lt;/SignsDescription&gt;
  &lt;/ANIMAL&gt;
  &lt;PARTIES&gt;
  &lt;POLICYHOLDER&gt;
  &lt;Type&gt;POLICY HOLDER&lt;/Type&gt;
  &lt;PERSON&gt;
  &lt;Title&gt;MRS&lt;/Title&gt;
  &lt;/ANIMALCONDITION&gt;
  &lt;/PERSON&gt;
  &lt;/POLICYHOLDER&gt;
  &lt;/PARTIES&gt;
  </code></pre>
  
  <p>The <code>&lt;/AnimalCondition&gt;</code> tag is in the wrong place and should be before <code>&lt;/Animal&gt;</code></p>
  
  <p>How do I fix this and ensure the closing tags are in the right place.</p>
  
  <p>Any help would be appreciated</p>
  
  <p>Thank you.</p>