Created
October 19, 2017 22:44
-
-
Save stemar/e5ab821a3d2a7b2e08c8d487fd8dc5d5 to your computer and use it in GitHub Desktop.
Convert XSD file to JSON file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function xsd_to_json($xsd_file, $formatted = 448) { | |
| $xml_file = preg_replace('/\.xsd$/', '.xml', $xsd_file); | |
| $json_file = preg_replace('/\.xsd$/', '.json', $xsd_file); | |
| $doc = new DOMDocument(); | |
| $doc->preserveWhiteSpace = true; | |
| $doc->load($xsd_file); | |
| $doc->save($xml_file); | |
| $xml = file_get_contents($xml_file); | |
| $obj = str_replace($doc->lastChild->prefix.':', "", $xml); | |
| $json = json_encode(simplexml_load_string($obj), $formatted); | |
| return file_put_contents($json_file, $json); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment