PHP code example of vierbergenlars / xml

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

    

vierbergenlars / xml example snippets


use vierbergenlars\Xml\XmlElement;

$simpleXml = new \SimpleXMLElement($xml);
$xmlElement = new XmlElement($simpleXml);


$totalPages = ceil($xmlElement->attr('total') / $xmlElement->attr('items_per_page'));
echo $xmlElement->attr('page') . '/' . $totalPages . "\n";

$files = $xmlElement->children();
/* @var $files XmlCollectionInterface */

foreach($files as $file) {
    /* @var $file XmlElementInterface */
    echo 'File ' . $file->attr('id') . ":\n";
    echo '  Filename: ' . $file->child('filename')->text() . "\n";

    echo "  Links:\n";
    foreach($file->children('link') as $link) {

        /* @var $link XmlElementInterface */
        echo '    ' . $link->attr('href');
        foreach($link->attributes() as $attr => $value) {

            if($attr != 'href')
                echo ' (' . $attr . '=' . $value . ')';
        }
        echo "\n";
    }

    echo '  Weblink: ' . $file->children('link')->find(array('rel'  => 'self', 'type' => 'www'))->get(0)->attr('href') . "\n";

//    echo '  Weblink: ' . $file->child('link', array('rel'  => 'self', 'type' => 'www'))->attr('href') . "\n";
}

echo 'Total: ' . $files->count() . "\n";