1. Go to this page and download the library: Download dcarbone/xml-writer-plus library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dcarbone / xml-writer-plus example snippets
use \DCarbone\XMLWriterPlus;
// Initialize writer instance
$xmlWriterPlus = new XMLWriterPlus();
// Start in-memory xml document
$xmlWriterPlus->openMemory();
$xmlWriterPlus->startDocument();
// Write out a comment prior to any elements
$xmlWriterPlus->writeComment('This is a comment and it contains superfluous information');
// Write root element (can be called anything you wish)
$xmlWriterPlus->startElement('Root');
// Write a node value to the root element
$xmlWriterPlus->text('Root element node value');
// Append a child element to the root element with it's own value
// This method opens, writes value, and closes an element all in one go
$xmlWriterPlus->writeElement('Child', 'Root element child element');
// Append a child element with some attributes in one go
$xmlWriterPlus->writeElement('AttributedChild', 'some data', ['attr' => 'value!', 'ns:attr' => 'other value!']);
// Insert a CDATA element
$xmlWriterPlus->writeCDataElement('MyCData', '<div>This div won\'t confuse XML Parsers! <br></div>');
// Close root element
$xmlWriterPlus->endElement();
// Make document immutable
$xmlWriterPlus->endDocument();
// See our XML!
echo htmlspecialchars($xmlWriterPlus->outputMemory());
/**
* @param string $prefix
* @param string $uri
*/
public function addNS($prefix, $uri);
/**
* @param string $prefix
*/
public function removeNS($prefix);
/**
* @param string $prefix
* @return bool
*/
public function hasNSPrefix($prefix);
/**
* @param string $uri
* @return bool
*/
public function hasNSUri($uri);
/**
* @return array
*/
public function getNSArray();
/**
* @param array $nsArray
*/
public function setNSArray(array $nsArray);
/**
* @param string $prefix
* @return string|bool
*/
public function getNSUriFromPrefix($prefix);
/**
* @param string $uri
* @return mixed
*/
public function getNSPrefixFromUri($uri);