PHP code example of kiwilan / php-xml-reader

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

    

kiwilan / php-xml-reader example snippets


use KiwiLan\XmlReader\XmlReader;

$xml = XmlReader::make('path/to/file.xml', bool $mapContent = true, bool $failOnError = true);

$content = $xml->getContents();

$title = $content['metadata']['dc:title'] ?? null;

$title = $xml->find('title', strict: false);

$dcTitle = $xml->find('dc:title');

$dcCreator = $xml->find('dc:creator', content: true);

$dcCreator = $xml->find('dc:creator', attributes: true);

$dc = $xml->search('dc');

$rootKey = $xml->extract('metadata');

$subSubKey = $xml->extract(['metadata', 'dc:title']);

$title = $xml->extract(['metadata', 'dc:title']);
$title = XmlReader::parseContent($title);

$creator = $xml->extract(['metadata', 'dc:creator']);
$creator = XmlReader::parseContent($creator);

$creatorAttributes = $xml->extract(['metadata', 'dc:creator']);
$creatorAttributes = XmlReader::parseAttributes($creatorAttributes);