title: Generating XML from HTML list using PHP
body: <p>I would like to convert the list structure in html:</p>
  
  <pre><code>&lt;ul&gt;
      &lt;li&gt;Section 1&lt;/li&gt;
      &lt;li&gt;Section 2
          &lt;ul&gt;
              &lt;li&gt;Section 2.1&lt;/li&gt;
              &lt;li&gt;Section 2.2&lt;/li&gt;
          &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Section 3&lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>Into XML like this:</p>
  
  <pre><code>&lt;sections&gt;
      &lt;section&gt;
          &lt;caption&gt;Section 1&lt;/caption&gt;
          &lt;level&gt;0&lt;/level&gt;
      &lt;/section&gt;
      &lt;section&gt;
          &lt;caption&gt;Section 2&lt;/caption&gt;
          &lt;level&gt;0&lt;/level&gt;
      &lt;/section&gt;
      &lt;section&gt;
          &lt;caption&gt;Section 2.1&lt;/caption&gt;
          &lt;level&gt;1&lt;/level&gt;
      &lt;/section&gt;
      &lt;section&gt;
          &lt;caption&gt;Section 2.2&lt;/caption&gt;
          &lt;level&gt;1&lt;/level&gt;
      &lt;/section&gt;
      &lt;section&gt;
          &lt;caption&gt;Section 3&lt;/caption&gt;
          &lt;level&gt;0&lt;/level&gt;
      &lt;/section&gt;
  &lt;/sections&gt;
  </code></pre>
  
  <p>I tried to use PHP SimpleXML to read in the html but it seems to have problem when it encounters an <code>&lt;ul&gt;</code> tag inside a <code>&lt;li&gt;</code> tag.</p>
  
  <p>I wonder if someone can kindly suggest what the simplest way is to get this done in PHP?</p>
  
  <p>Many thanks to you all.</p>