As we know that 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. Below are few easy steps to convert .xsd file into associative array.
Step 1: First load .xsd file.
Step 2: Save .xsd file as an xml file.
Step 3: Generate xml as a string and removed xsd prefixes.
- $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.
- $xml_string= simplexml_load_string($parseObj);
- $json = json_encode($ob);
- $data = json_decode($json, true);
- echo “<pre>”;