Home » » Convert .xsd file into array in PHP

Convert .xsd file into array in PHP

Written By Unknown on Jumat, 21 Juni 2013 | 02.29

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.

   $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);
 
Share this article :

Posting Komentar

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Kumpulan Kata Broadcast Blackberry - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger