PHP has no direct function to convert .xsd (XML Schema Definition) file into associative array like XML file. So you have to first convert .xsd file into xml then finally parse xml file into associative array.
Also, read:
- Convert Associative Array into XML in PHP
- Convert XML into Associative Array in PHP
- Converting an Array to JSON in PHP
- Converting JSON to Array or Object in PHP
Below are few easy steps to convert .xsd file into associative array.
Step 1: First load .xsd file.
<?php $doc->preserveWhiteSpace = true; $doc->load('yourfile.xsd'); ?>
Step 2: Save .xsd file as an xml file.
<?php $doc->save('myxml.xml'); ?>
Step 3: Generate xml as a string and removed xsd prefixes.
<?php $myxmlfile = file_get_contents('myxml.xml'); $parseObj = str_replace($doc->lastChild->prefix.':',"",$myxmlfile); ?>
finally .xsd file converted into xml file, Now we will use simplexml_load_string PHP function to get array.
<?php $xml_string= simplexml_load_string($parseObj); $json = json_encode($ob); $data = json_decode($json, true); print_r($data); ?>
You may also like:
- Working with php.ini file Configuration
- Control Statements in PHP
- Convert Associative Array into XML in PHP
- Convert XML into Associative Array in PHP
- Using Prepared Statement with PHP & MySQL
- How to Upload File in PHP
- Converting an Array to JSON in PHP
- Converting JSON to Array or Object in PHP
- Manipulating PHP arrays: push, pop, shift, unshift
- Remove Repeated Words From String in PHP
- Converting a PHP Array to a Query String
- 15+ regular expressions for PHP developers
- 10 Most Important Directory Functions in PHP
- 10 little known but useful PHP functions
- PHP Script to Download Large Files Reliably