PHP code example of stein197 / xml-builder

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

    

stein197 / xml-builder example snippets



use STEIN197\XMLBuilder\Builder;

$builder = (new Builder)
->html(function($html) {
	$html
	->head()
	->body();
});
echo $builder;

(new Builder)
->camelCased(/* ... */); // -> <camel-cased/>

(new Builder)
->snake_cased(/* ... */); // -> <snake:cased/>

(new Builder)
->under__score(/* ... */); // -> <under_score/>

(new Builder)
->tag('custom.TagName_', ['attr' => 'value']); // -> <custom.tagname attr="value"/>

(new Builder)
->cdata('cdata') // <![CDATA[cdata]]>
->comment('comment'); // <!-- comment -->

echo (new Builder(['version' => '1.0'])); /* <?xml version="1.0"

echo $builder->stringify(Builder::OUTPUT_MINIFIED, Builder::MODE_HTML);
// or
echo $builder->stringify(Builder::OUTPUT_BEAUTIFIED, Builder::MODE_XML);

(new Builder)
->html(function($html) {
	$html
	->head(function($head) {
		$head
		->link(/* ... */);
	});
});

(new Builder)
->html(function($html) {
	$html
	->body('content', [
		'class' => 'index'
	]);
});

// <body class="index">content</body>

$b1 = (new Builder)
->p('Text');
echo (new Builder)
->div($b1);
// <div><p>Text</p></div>

(new Builder)
->svg(function($svg) {
	$svg->path(); // Does not affect the tree
	return '<path/>';
});
// <svg><path/></svg>