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);

use Kiwilan\XmlReader\XmlReader;

$xml = XmlReader::make('path/to/file.xml');
$contents = $xml->getContents();

use Kiwilan\XmlReader\XmlReader;

$xml = XmlReader::make('path/to/file.xml');
$contents = $xml->getContents();
$title = $contents['metadata']['dc:title'] ?? null;

use Kiwilan\XmlReader\XmlReader;

$xml = XmlReader::make('path/to/file.xml');
$title = $xml->find('title', strict: false);

use Kiwilan\XmlReader\XmlReader;

$xml = XmlReader::make('path/to/file.xml');
$dcTitle = $xml->find('dc:title');

use Kiwilan\XmlReader\XmlReader;

$xml = XmlReader::make('path/to/file.xml');
$dcCreator = $xml->find('dc:creator', content: true);

use Kiwilan\XmlReader\XmlReader;

$xml = XmlReader::make('path/to/file.xml');
$dcCreator = $xml->find('dc:creator', attributes: true);

use Kiwilan\XmlReader\XmlReader;

$xml = XmlReader::make('path/to/file.xml');
$dc = $xml->search('dc');

use Kiwilan\XmlReader\XmlReader;

$xml = XmlReader::make('path/to/file.xml');
$rootKey = $xml->extract('metadata');

use Kiwilan\XmlReader\XmlReader;

$xml = XmlReader::make('path/to/file.xml');
$subSubKey = $xml->extract(['metadata', 'dc:title']);

use Kiwilan\XmlReader\XmlReader;

$xml = XmlReader::make('path/to/file.xml');
$title = $xml->extract(['metadata', 'dc:title']);
$title = XmlReader::parseContent($title);

use Kiwilan\XmlReader\XmlReader;

$xml = XmlReader::make('path/to/file.xml');
$creator = $xml->extract(['metadata', 'dc:creator']);
$creator = XmlReader::parseContent($creator);

use Kiwilan\XmlReader\XmlReader;

$xml = XmlReader::make('path/to/file.xml');
$creatorAttributes = $xml->extract(['metadata', 'dc:creator']);
$creatorAttributes = XmlReader::parseAttributes($creatorAttributes);