PHP code example of logifire / xml
1. Go to this page and download the library: Download logifire/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/ */
logifire / xml example snippets
$xml = <<<XML
<root xmlns="https://example.org">
<string attribute="first">Hello World</string>
<int>100</int>
<string attribute="second">Hello Internet</string>
</root>
XML;
$namespace = 'https://example.org';
$prefix = 'p';
$reader = Reader::create($xml, $namespace, $prefix);
// Absolute path
$reader->hasNode('/p:root'); // true
$reader->getString('/p:root/p:string[@attribute="first"]'); // Hello World
$reader->getInt('/p:root/p:int'); // 100
// Relative path
$collection = $reader->getCollection('/p:root/p:string');
$string_reader = $collection[0];
$string_reader->getName(); // string
$string_reader->getString('@attribute'); // first