PHP code example of originphp / xml

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

    

originphp / xml example snippets


use Origin\Xml\Xml;
$data = [
    'post' => [
        '@category' => 'how tos', // to set attribute use @
        'id' => 12345,
        'title' => 'How to create an XML block',
        'body' =>  Xml::cdata('A quick brown fox jumps of a lazy dog.'),
        'author' => [
            'name' => 'James'
            ]
        ]
];
    
$xml = Xml::fromArray($data);

$xml = Xml::fromArray($data,[
        'version' => '1.0',
        'encoding' => 'UTF-8',
        'pretty' => true
        ]);

$data = [
'charges' => [
    'charge' => [
        [
            'amount' => 10,
            'description' => 'Shipping',
        ],
        [
            'amount' => 35,
            'description' => 'Tax',
        ],
        ]
    ]
];

$data = [
    'task' => [
        '@id' => 128,
        'name' => 'Buy milk',
        '@' => 'some text'
    ]
];

$xml = '<?xml version="1.0" encoding="utf-8"

$data = [
'book' => [
    'xmlns:' => 'http://www.w3.org/1999/xhtml',
    'title' => 'Its a Wonderful Day'
    ]
];
$xml = Xml::fromArray($data);

$data = [
    'student:record' => [
        'xmlns:student' => 'https://www.originphp.com/student',
        'student:name' => 'James',
        'student:phone' => '07986 123 4567'
    ]
];

$data = [
    'book' => [
        'xmlns:' => 'urn:loc.gov:books',
        'xmlns:isbn' => 'urn:ISBN:0-395-36341-6',
        'title' => 'Cheaper by the Dozen',
        'isbn:number' => '1568491379' 
    ]
];