Search code examples
phpxmlwriter

XMLWriter add new element to document start


Flow is like that:

    $xml = new XMLWriter();
    $xml->openURI('file.xml');
    $xml->setIndent(4);
    $xml->startDocument('1.0');

    $xml->startElement('second');
    $xml->endElement(); 

Now I want add element at start (before second)

    $xml->startElement('first');
    $xml->endElement(); 

How I can mode element first before second ?


Solution

  • XMLWriter not have option to manipulate with nodes (apend after, apend before), so no build in solution for that issue.