title: Is there a simple way to create a custom PHP XML writer function?
body: <p>I'm developing a PHP web API (using Laravel Lumen) that outputs XML but writing the XML structures and attributes is getting out of hand, is there a simple way to create a custom function that shortens the codebase?</p>
  
  <p>I'm using PHP's <code>$xml = new \XMLWriter();</code> and writing code such as:</p>
  
  <pre><code>$xml-&gt;startElement('DataStructure');
  $xml-&gt;writeAttribute('version', "1.0");
  </code></pre>
  
  <p>What i would like to do is something like:</p>
  
  <pre><code>$xml-&gt;startElement('DataStructure');
  $this-&gt;api_version();
  
  where
  
  function api_version() {
      $xml-&gt;writeAttribute('version', "1.0");
  }
  </code></pre>