title: Convert XML to Object in PHP and again convert that Object to XML?
body: <p>Lets say I have a XML as below -</p>
  
  <pre><code>$xml = '&lt;?xml version="1.0"?&gt;
  &lt;step number="9"&gt;
    &lt;s_name&gt;test&lt;/s_name&gt;
    &lt;b_sel&gt;12345&lt;/b_sel&gt;
    &lt;b_ind&gt;7&lt;/b_ind&gt;
  &lt;/step&gt;';
  </code></pre>
  
  <p>I want this to be converted to object, but when I perform below steps, it gives me stdclass object as below [I am assigning it to $stepInformation variable] - </p>
  
  <pre><code>$xml = json_decode(json_encode((array) simplexml_load_string($xml)), 1);
  
  $stepInformation = stdClass Object
  (
      [@attributes] =&gt; Array
          (
              [number] =&gt; 9
          )
  
      [s_name] =&gt; test
      [b_sel] =&gt; 12345
      [b_ind] =&gt; 7
  )
  </code></pre>
  
  <p>So when I am parsing this stdclass object in a php function</p>
  
  <pre><code>function convertStepInformationToArray($stepInformation)
  {
       $dom = new DOMDocument();
      $stepInfo = "{$stepInformation-&gt;s_name}{$stepInformation-&gt;b_sel}{$stepInformation-&gt;b_ind}";    
  $dom-&gt;loadXML("&lt;document&gt;" . $stepInfo . "&lt;/document&gt;");
      $domx = new DOMXPath($dom);
      $entries = $domx-&gt;evaluate("//step");
      return $entries;
  }
  </code></pre>
  
  <p>The output I am getting is </p>
  
  <pre><code>DOMNodeList Object
  (
      [length] =&gt; 0
  )
  </code></pre>
  
  <p>I want <code>[length] =&gt; 1</code> to proceed with my project. I know the problem is with the <code>&lt;step number="9"&gt;</code> which is coming as below after converting it to object.</p>
  
  <pre><code>stdClass Object
      (
          [@attributes] =&gt; Array
              (
                  [number] =&gt; 9
              )
  </code></pre>
  
  <p><strong>NOTE</strong>- I have even tried with below steps but no luck:</p>
  
  <pre><code>$xml = simplexml_load_string($xml);
  
  $stepInformation = SimpleXMLElement Object
          (
              [@attributes] =&gt; Array
              (
                  [number] =&gt; 9
              )
  
          [s_name] =&gt; test
          [b_sel] =&gt; 12345
          [b_ind] =&gt; 7
  )
  </code></pre>
  
  <p>Could you guys please give me some pointers on this, how can I get the output as below ? Any alternative approach would be Ok, as long as I am getting the exact output -</p>
  
  <pre><code>   DOMNodeList Object
      (
          [length] =&gt; 1
      )
  </code></pre>
  
  <p>Any help on this would be appreciated. </p>
  
  <p>Thank you.</p>