In this tutorial, I will describe how to convert xsd into an associative array. I had googled for this but unfortunately – I did not find a useful answer.
Here, I am sharing my thoughts, How to find an array from an XSD file, since there is no method in PHP to directly parse XSD file into an Array-like XML file. So I have used a trick to convert XSD into xml file and then into an array.
Also checkout other related tutorials,
If you are more comfortable in watching a video that explains about xsd to array in php, then you should watch this video tutorial.
We’ll follow the following steps to converts XSD into the array.
Step 1: Load xsd file using php load()
into document domain.
$doc->preserveWhiteSpace = true; $doc->load('test.xsd');
Step 2: Save xsd file as an xml file.
$doc->save('t.xml');
Step 3: Generate xml as a string and remove xsd prefix.
$xmlfile = file_get_contents('t.xml'); $parseObj = str_replace($doc->lastChild->prefix.':',"",$xmlfile);
Finally, We have converted XSD into an XML file, Let’s use the XML lib function of PHP to get an array.
Step 4: Load xml string and convert into array.
$ob= simplexml_load_string($parseObj); $json = json_encode($ob); $data = json_decode($json, true); echo ""; print_r($data);
<?php $doc--->$preserveWhiteSpace = true; $doc->load('test.xsd'); $doc->save('t.xml'); $xmlfile = file_get_contents('t.xml'); $parseObj = str_replace($doc->lastChild->prefix.':',"",$xmlfile); $ob= simplexml_load_string($parseObj); $json = json_encode($ob); $data = json_decode($json, true); echo ""; print_r($data); ?>
This tutorial helps integrate a PHP SDK with Laravel. We'll install aws-php-sdk into laravel application and access all aws services… Read More
in this quick PHP tutorial, We'll discuss php_eol with examples. PHP_EOL is a predefined constant in PHP and represents an… Read More
This Laravel tutorial helps to understand table Relationships using Elequonte ORM. We'll explore laravel table Relationships usage and best practices… Read More
We'll explore different join methods of Laravel eloquent with examples. The join helps to fetch the data from multiple database… Read More
in this Laravel tutorial, We'll explore valet, which is a development environment for macOS minimalists. It's a lightweight Laravel development… Read More
I'll go through how to use soft delete in Laravel 10 in this post. The soft deletes are a method… Read More