title: XML - Get parent of selected node
body: <p>I have a project, where I am selecting a scene based on the information in a <code>Tree</code>'s XML data provider.</p>
  
  <p>As you can see in my XML below, I've got two scenes.  Each have a <code>view001</code> attribute, which only exists at the highest level in the tree hierarchy.  What I need to do, is to find out the information stored in this attribute. </p>
  
  <p>I need to see only the one that contains the currently selected item in my Tree (named <code>treeView</code>, dataProvider is the xml file, labelfield is <code>.@name</code>).</p>
  
  <p>One problem I do know I have, is that I'm only checking the first <code>parent()</code>. My problem is, that I don't know how to "step" through the XML, to go up one parent at a time. I think this might be my only problem, too..</p>
  
  <p>This is my function:</p>
  
  <pre><code>public function getParentItem():XML {
      var selectedItem:XML = new XML(treeView.selectedItem);
  
      while(selectedItem.@view001.toString() == "") {
          try{
              selectedItem = treeView.selectedItem.parent();
          } catch(err:Error) {
              trace("Error: No parents found!");
              return null;
          }
      }
      return selectedItem;
  }
  </code></pre>
  
  <p>This is my XML file:</p>
  
  <pre><code>&lt;importInfo name="Main" cImageW="2880" cImageH="1620" dImageW="2880" dImageH="1620" bImageW="1280" bImageH="720" aspectRatio="16/9"&gt;
  &lt;objects name="ENI Goliat 360"&gt;
      &lt;object name= "Area A" color="010101" length="1300.54" width="1300.54" height="1300.54" posx="-140.48" posy="-259.226" posz="57.6476" view001="Template_View001" view002="Template_View002" view003="Template_View003"&gt;
          &lt;object name= "Template" color="010111" length="910.45" width="1308.06" height="360.91" posx="-197.153" posy="-119.162" posz="-67.1688" &gt;
              &lt;object name= "Vacum Lid" color="010121" length="-1000.54" width="-732.224" height="14.029" posx="375.825" posy="367.99" posz="-60.4437" LastPose =" undefined" /&gt;
              &lt;object name= "Xmas Tree 1" color="010131" length="209.81" width="185.618" height="176.285" posx="-140.48" posy="-259.226" posz="57.6476" LastPose =" undefined" &gt;
                  &lt;object name= "Control Module 1" color="010141" length="33.8371" width="33.8371" height="71.277" posx="-210.844" posy="-274.111" posz="49.6147" LastPose =" undefined" /&gt;
              &lt;/object&gt; 
              &lt;object name= "Xmas Tree 2" color="010151" length="209.81" width="185.618" height="176.285" posx="157.511" posy="-259.226" posz="57.6476" LastPose =" undefined" &gt;
                  &lt;object name= "Control Module 2" color="010161" length="33.8371" width="33.8371" height="71.277" posx="87.1474" posy="-274.111" posz="49.6147" LastPose =" undefined" /&gt;
              &lt;/object&gt; 
              &lt;object name= "Xmas Tree 3" color="010171" length="-209.81" width="-185.618" height="176.285" posx="-139.859" posy="300.043" posz="57.6476" LastPose =" undefined" &gt;
                  &lt;object name= "Control Module 3" color="010181" length="-33.837" width="-33.8371" height="71.277" posx="-69.4951" posy="314.927" posz="49.6147" LastPose =" undefined" /&gt;
              &lt;/object&gt; 
              &lt;object name= "Xmas Tree 4" color="010191" length="-209.81" width="-185.618" height="176.285" posx="157.678" posy="300.043" posz="57.6476" LastPose =" undefined" &gt;
                  &lt;object name= "Control Module 4" color="0101a1" length="-33.837" width="-33.8371" height="71.277" posx="228.042" posy="314.927" posz="49.6147" LastPose =" undefined" /&gt;
              &lt;/object&gt; 
              &lt;object name= "Hatches" color="0d0dd9" length="853.092" width="641.077" height="38.6531" posx="8.64197" posy="20.1918" posz="166.54" LastPose =" undefined" /&gt;
              &lt;object name= "Manifold" color="0101c1" length="348.443" width="1055.62" height="256.673" posx="8.81242" posy="19.8837" posz="-47.4717" LastPose =" undefined" &gt;
                  &lt;object name= "Umbilical" color="0101d1" length="15.6839" width="-1067.38" height="30.0319" posx="160.286" posy="-42.1586" posz="-14.7542" LastPose =" undefined" /&gt;
                  &lt;object name= "SAM Hatch" color="0101e1" length="104.111" width="162.785" height="23.9263" posx="8.81239" posy="6.30106" posz="186.356" LastPose =" undefined" /&gt;
                  &lt;object name= "SAM Hatch" color="0101f1" length="-104.111" width="-162.785" height="23.9263" posx="8.76724" posy="33.4806" posz="186.356" LastPose =" undefined" /&gt;
                  &lt;object name= "Manifold Cover" color="011101" length="208.662" width="639.95" height="0.393707" posx="8.81241" posy="19.8837" posz="-47.4717" LastPose =" undefined" /&gt;
                  &lt;object name= "Sealine Cover" color="011111" length="-228.002" width="1206.52" height="235.54" posx="-352.163" posy="19.8837" posz="124.118" /&gt;
              &lt;/object&gt; 
          &lt;/object&gt; 
          &lt;object name= "10' Oil Eeas(SP06) TEE - TEMPLATE C" color="011121" length="33.8898" width="1473.6" height="89.1353" posx="-1924.2" posy="1175.54" posz="2402.62" /&gt;
          &lt;object name= "10' Oil West(SP05) TEE - TEMPLATE C" color="011131" length="18.9734" width="1373.77" height="80.3972" posx="-1933.05" posy="624.902" posz="2402.62" /&gt;
          &lt;object name= "6' Gas(GL02) TEMPLATE B - TEMPLATE C" color="011141" length="1350.58" width="2542.36" height="144.254" posx="14156.9" posy="19699.3" posz="2401.68" /&gt;
          &lt;object name= "Umbilical(UM05) TEMPLATE B - TEMPLATE C" color="011151" length="1313.2" width="2942.5" height="137.481" posx="13516.9" posy="18206.4" posz="2402.62" /&gt;
          &lt;object name= "Umbilical(UM05) TEMPLATE C - TEMPLATE I" color="011161" length="55.0352" width="1288.32" height="64.1479" posx="-50077.3" posy="-60757.5" posz="2402.62" /&gt;
          &lt;object name= "6' Gas(GL03) TEMPLATE C - TEMPLATE D" color="011171" length="-10.2617" width="1537.04" height="85.0139" posx="-33206.3" posy="-34778.7" posz="2402.62" /&gt;
      &lt;/object&gt;
      &lt;object name="Goliat Sevan" color="57e157" length="4912.53" width="4912.53" height="4912.53" posx="-119.385" posy="-2970.76" posz="403.785" view001="Topside_View001" view002="" view003="" &gt;
          &lt;object name="Boom" color="640404" length="-651.017" width="1611.94" height="3641.64" posx="-169.37" posy="-2888.7" posz="3569.63" /&gt;
          &lt;object name="Production" color="8c0606" length="-3499.51" width="5256.08" height="1946.97" posx="875.004" posy="-1031.51" posz="1702.66" /&gt;
          &lt;object name="Lifeboats" color="780505" length="564.514" width="-3529.38" height="819.231" posx="-1337.81" posy="-4437.18" posz="1629.08" LastPose ="undefined" /&gt;
          &lt;object name="Living Quarter" color="a00707" length="-1644.94" width="2099.55" height="1663.29" posx="-1716.48" posy="-3341.02" posz="1838.31" /&gt;
          &lt;object name="Cranes" color="3c0303" length="-6720.73" width="1488.25" height="1516.48" posx="-561.582" posy="-4616.26" posz="2068.74" /&gt;
          &lt;object name="Hull" color="280101" length="-3784.79" width="5998.56" height="2413.14" posx="-119.385" posy="-2970.76" posz="403.785" /&gt;
          &lt;object name="Knudsen Shipping" color="b40808" length="-10560.2" width="100.002" height="2250.03" posx="2164.21" posy="-17398.6" posz="-493.164" LastPose ="undefined" /&gt;
      &lt;/object&gt; 
  &lt;/objects&gt;
  </code></pre>
  
  <p></p>