PHP code example of arc / xml

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

    

arc / xml example snippets


    use \arc\xml as x;
    $xmlString = 
        x::preamble()
        .x::rss(['version'=>'2.0'],
             x::channel(
                 x::title('Wikipedia'),
                 x::link('http://www.wikipedia.org'),
                 x::description('This feed notifies you of new articles on Wikipedia.')
             )
        );

    $xml = \arc\xml::parse($xmlString);
    $title = $xml->channel->title->nodeValue; // SimpleXMLElement 'Wikipedia'
    $titleTag = $xml->channel->title; // <title>Wikipedia</title>
    echo $title;

    $xml = \arc\xml::parse( $xmlString );
    $title = $xml->channel->title;
    echo $title;

    $title = $xml->channel->title->nodeValue;
    echo $title;

    $xml->channel->title = 'Update title';

    $about = $xml->channel['rdf:about'];

    $xml->channel['title-attribute'] = 'This is a title attribute'; 

   unset($xml->channel['title-attribute']);

    $items = $xml->find('item');
    echo implode($items);

    $xml->registerNamespace('dublincore','http://purl.org/dc/elements/1.1/');
    $date = current($xml->find('dublincore|date));
    echo $date;

    $version = $xml['version'];
    $version = $xml->attributes('version');

    $title = $xml->channel->title;

    $version = $xml->getAttributes('version');
    $title = $xml->getElementsByTagName('channel')[0]
        ->getElementsByTagName('title')[0];

    $xmlString = <<< EOF
<item>
    <title>An item</title>
</item>
<item>
    <title>Another item</title>
</item>
EOF;
    $xml = \arc\xml::parse($xmlString);
    echo $xml;