title: how to parse xml file with CDATA to an associative array in PHP
body: <p>all,</p>
  
  <p>I have a inputXml.xml file as below:</p>
  
  <pre><code>&lt;content&gt;
  &lt;item  name="book" label="Book"&gt;
  &lt;![CDATA[ book name ]]&gt;
  &lt;/item&gt;
  &lt;item  name="price" label="Price"&gt;
  &lt;![CDATA[ 35 ]]&gt;
  &lt;/item&gt;
  &lt;/content&gt;
  </code></pre>
  
  <p>And when I use code as below to parse the xml file:</p>
  
  <pre><code>$obj = simplexml_load_string(file_get_contents($inputXml),'SimpleXMLElement', LIBXML_NOCDATA);
  $json = json_encode($obj);
  $inputArray = json_decode($json,TRUE);
  </code></pre>
  
  <p>I get the array like below:</p>
  
  <pre><code>[content] =&gt; Array
              (
                  [item] =&gt; Array
                      (
                          [0] =&gt; book name
                          [1] =&gt; 35
                      )
  
              )
  </code></pre>
  
  <p>I am wondering, is it possible to get an associative array by using the value of the attributes "name" or "label" as the key as below:</p>
  
  <pre><code>[content] =&gt; Array
              (
                  [item] =&gt; Array
                      (
                          [name] =&gt; book name
                          [price] =&gt; 35
                      )
  
              )
  </code></pre>