title: How to import XML to MySQL with parent and child elements?
body: <p>Using the following query I can read all <code>&lt;vehicle&gt;</code> elements from the XML and save it into database but I want that each vehicle also store its parent <code>&lt;timestep&gt;</code> <code>time</code> so that I know which time step it belongs to.</p>
  
  <p><strong>query</strong></p>
  
  <pre><code>LOAD XML LOCAL INFILE 'vehicle.xml'
  INTO TABLE vehicles
  ROWS IDENTIFIED BY '&lt;vehicle&gt;'
  </code></pre>
  
  <p>I tired creating a table timesteps where I added a time column and all the other columns too but it gets the last vehicle from each timestep only!, while I want to get all the children.</p>
  
  <p><strong>Part of my XML</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;fcd-export xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/fcd_file.xsd"&gt;
      &lt;timestep time="0.00"&gt;
          &lt;vehicle id="0" x="3654.27" y="3699.20" angle="327.39" type="DEFAULT_VEHTYPE" speed="0.00" pos="5.10" lane="21059650#7_0" slope="0.00"/&gt;
      &lt;/timestep&gt;
      &lt;timestep time="1.00"&gt;
          &lt;vehicle id="0" x="3653.49" y="3700.41" angle="327.39" type="DEFAULT_VEHTYPE" speed="1.44" pos="6.54" lane="21059650#7_0" slope="0.00"/&gt;
          &lt;vehicle id="1" x="2592.95" y="3497.59" angle="60.95" type="DEFAULT_VEHTYPE" speed="0.00" pos="5.10" lane="22408082_0" slope="0.00"/&gt;
      &lt;/timestep&gt;
      &lt;timestep time="2.00"&gt;
          &lt;vehicle id="0" x="3651.81" y="3703.04" angle="327.39" type="DEFAULT_VEHTYPE" speed="3.12" pos="9.66" lane="21059650#7_0" slope="0.00"/&gt;
          &lt;vehicle id="1" x="2595.17" y="3498.82" angle="60.95" type="DEFAULT_VEHTYPE" speed="2.54" pos="7.64" lane="22408082_0" slope="0.00"/&gt;
          &lt;vehicle id="2" x="4551.99" y="4411.11" angle="328.95" type="DEFAULT_VEHTYPE" speed="0.00" pos="5.10" lane="23657587_0" slope="0.00"/&gt;
      &lt;/timestep&gt;
      &lt;timestep time="3.00"&gt;
          &lt;vehicle id="0" x="3649.14" y="3707.21" angle="327.39" type="DEFAULT_VEHTYPE" speed="4.95" pos="14.61" lane="21059650#7_0" slope="0.00"/&gt;
          &lt;vehicle id="1" x="2599.61" y="3501.29" angle="60.95" type="DEFAULT_VEHTYPE" speed="5.08" pos="12.73" lane="22408082_0" slope="0.00"/&gt;
          &lt;vehicle id="2" x="4550.98" y="4412.79" angle="328.95" type="DEFAULT_VEHTYPE" speed="1.96" pos="7.06" lane="23657587_0" slope="0.00"/&gt;
          &lt;vehicle id="3" x="4460.55" y="5390.34" angle="58.38" type="DEFAULT_VEHTYPE" speed="0.00" pos="5.10" lane="-22975228#1_0" slope="0.00"/&gt;
      &lt;/timestep&gt;
      &lt;timestep time="4.00"&gt;
          &lt;vehicle id="0" x="3645.25" y="3713.30" angle="327.39" type="DEFAULT_VEHTYPE" speed="7.23" pos="21.83" lane="21059650#7_0" slope="0.00"/&gt;
          &lt;vehicle id="1" x="2605.71" y="3504.68" angle="60.95" type="DEFAULT_VEHTYPE" speed="6.98" pos="19.70" lane="22408082_0" slope="0.00"/&gt;
          &lt;vehicle id="2" x="4549.12" y="4415.87" angle="328.95" type="DEFAULT_VEHTYPE" speed="3.59" pos="10.66" lane="23657587_0" slope="0.00"/&gt;
          &lt;vehicle id="3" x="4461.94" y="5391.20" angle="58.38" type="DEFAULT_VEHTYPE" speed="1.63" pos="6.73" lane="-22975228#1_0" slope="0.00"/&gt;
          &lt;vehicle id="4" x="6607.38" y="6648.96" angle="238.83" type="DEFAULT_VEHTYPE" speed="0.00" pos="5.10" lane="22983344_0" slope="0.00"/&gt;
      &lt;/timestep&gt;
      &lt;timestep time="5.00"&gt;
          &lt;vehicle id="0" x="3640.37" y="3720.81" angle="326.68" type="DEFAULT_VEHTYPE" speed="8.95" pos="30.78" lane="21059650#7_0" slope="0.00"/&gt;
          &lt;vehicle id="1" x="2613.55" y="3509.03" angle="60.95" type="DEFAULT_VEHTYPE" speed="8.97" pos="28.67" lane="22408082_0" slope="0.00"/&gt;
          &lt;vehicle id="2" x="4545.93" y="4421.17" angle="328.95" type="DEFAULT_VEHTYPE" speed="6.19" pos="16.84" lane="23657587_0" slope="0.00"/&gt;
          &lt;vehicle id="3" x="4465.05" y="5393.11" angle="58.38" type="DEFAULT_VEHTYPE" speed="3.64" pos="10.37" lane="-22975228#1_0" slope="0.00"/&gt;
          &lt;vehicle id="4" x="6605.78" y="6648.00" angle="238.83" type="DEFAULT_VEHTYPE" speed="1.86" pos="6.96" lane="22983344_0" slope="0.00"/&gt;
          &lt;vehicle id="5" x="6028.95" y="3131.17" angle="40.09" type="DEFAULT_VEHTYPE" speed="0.00" pos="5.10" lane="264312282#1_0" slope="0.00"/&gt;
      &lt;/timestep&gt;
  &lt;/fcd-export&gt;
  </code></pre>