PHP code example of evrenonur / xml2json

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

    

evrenonur / xml2json example snippets


    use  Onur\Xml2json\XmlToJson;
    
    // Load XML from a file  
    $xmlNode = simplexml_load_file('path/to/your/file.xml');
    
    // Create an instance of XmlToJson
    $xmlToJson = new  XmlToJson();
      
    // Convert XML to JSON and echo the result  
    echo  $xmlToJson->xmlToJson($xmlNode);

    $options = [ 
    'namespaceRecursive' => true,
    'removeNamespace' => false,
      // ... other options
     ]; 
     
  $xmlArray = $xmlToJson->xmlToArray($xmlNode, $options);