How To Convert .xsd File Into Array In PHP

Jun 19, 2013, by admin

We could not convert .xsd file into php array to convert that we should first convert the .xsd file into xml file then finally parse xml file into associative array the way of method to convert was given bekow

Step 1: First load .xsd file.

  $doc->preserveWhiteSpace = true;
    $doc->load(‘yourfile.xsd’);

Step 2: Save .xsd file as an xml file.

  $doc->save(‘myxml.xml’);

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>”;
    print_r($data);

Hope the post will be useful like the page Bugtreat Technologies  for updates for any other queries contact @ support@bugtreat.com