PHP code example of panda / dom

1. Go to this page and download the library: Download panda/dom 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/ */

    

panda / dom example snippets


use Panda\Ui\Dom\Handlers\DOMHandler;

// Normal DOMElement way
// The same way for get and remove
// Where $element is a DOMElement object
$element->setAttribute($name = 'id', $value = 'id_value');


// Using DOMHandler
$handler = new DOMHandler();

// Set an attribute
$handler->attr($element, $name = 'id', $value = 'id_value', $validate = false);

// Get an attribute
$handler->attr($element, $name = 'id');

// Remove an attribute
$handler->attr($element, $name = 'id', $value = null);

use Panda\Ui\Dom\Handlers\DOMHandler;
use \Panda\Ui\Dom\Factories\DOMFactory;
use \Panda\Ui\Dom\DOMPrototype;

// Create a handler instance
$handler = new DOMHandler();

// Create a new factory instance
$factory = new DOMFactory();

// Create a document and provide the handler and factory
$document = new DOMPrototype($handler, $factory);


// Get the factory and build an element
$document->getDOMFactory()->buildElement($name = 'div', $value = 'value');

// Document uses the above function with a 'facade' function called create:
$document->create($name = 'div', $value = 'value');

class DOMItem extends DOMElement
{
}

class DOMPrototype extends DOMDocument
{
}

use Panda\Ui\Dom\Handlers\DOMHandler;
use \Panda\Ui\Dom\Factories\DOMFactory;
use \Panda\Ui\Dom\DOMPrototype;

// Create the document
// Using a container here would make the call a lot easier
$DOMHandler = new DOMHandler();
$DOMFactory = new DOMFactory();
$document = new DOMPrototype($DOMHandler, $DOMFactory);

// Create the root element and append it to the document
$root = $document->create($name = 'root', $value = '');
$document->append($root);

// Create an element and append it to the root
$element = $document->create($name = 'child', $value = 'This is a root child.');
$root->append($element);

use \Panda\Ui\Dom\DOMPrototype;
use \Panda\Ui\Dom\DOMItem;

// Create the document to associate the DOMItem with
$document = new DOMPrototype(new DOMHandler(), new DOMFactory());

// Create the item
$item = new DOMItem($document, $name = 'div', $value = '');

// Update the item
$item->attr('name', 'item_name');
$item->attr('title', 'item_title');

// Append item to document
$document->append($item);