PHP code example of noki / xml-converter

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

    

noki / xml-converter example snippets


use Noki\XmlConverter\Convert;

$json = Convert::xmlToJson($xmlString);

$array = Convert::xmlToArray($xmlString);

$array = Convert::xmlToArray(
    $xmlString,
    namespace_in_tag_name: true,
    is_cdata: true,
    schema_path: '/path/to/schema.xsd' // or '' to enable DTD validation
);

$json = Convert::xmlToJson(
    $xmlString,
    namespace_in_tag_name: true,
    is_cdata: false,
    schema_path: null
);

$xml = <<<XML
<book xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="book.xsd">
    <title><![CDATA[The Great Gatsby]]></title>
    <author>F. Scott Fitzgerald</author>
    <year>1925</year>
</book>
XML;

$json = Convert::xmlToJson($xml, true, true, '/path/to/book.xsd');

use Noki\XmlConverter\Convert;

$data = Convert::xmlToArray($request->getContent(), true);
bash
sudo apt-get update
sudo apt-get install php-simplexml php-xml php-dom
bash
php -v
bash
brew install php
# OR, if PHP is already installed:
brew reinstall php
ini
extension=simplexml
extension=dom
extension=libxml