{"id":1492,"date":"2016-02-02T11:05:13","date_gmt":"2016-02-02T11:05:13","guid":{"rendered":"http:\/\/grodansparadis.com\/wordpress\/?p=1492"},"modified":"2017-12-11T08:13:56","modified_gmt":"2017-12-11T08:13:56","slug":"get-mdf-content-in-json-or-jsonp","status":"publish","type":"post","link":"https:\/\/grodansparadis.com\/wordpress\/?p=1492","title":{"rendered":"#VSCP HOWTO: Get MDF content in JSON or JSONP"},"content":{"rendered":"<p>To get a XML file in JavaScript can be difficult due to the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Same-origin_policy\">same origin policy<\/a>.\u00a0 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Cross-origin_resource_sharing\">CORS<\/a> is on solution but using\u00a0 <a href=\"https:\/\/en.wikipedia.org\/wiki\/JSONP\">JSONP<\/a> is a much simpler solution also because JavaScript kind of like the JSON format.<\/p>\n<p>The problem here for VSCP is that the <a href=\"http:\/\/www.vscp.org\/docs\/vscpspec\/doku.php?id=module_description_file\">MDF (Module Description File)<\/a> is in XML format. We therefore need a conversion.<\/p>\n<p>This PHP scripts will handle this and out put a local xml file in JSON\/JSONP format<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2016\/02\/Screenshot-from-2016-02-02-115050.png\" rel=\"attachment wp-att-1495\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1495\" data-permalink=\"https:\/\/grodansparadis.com\/wordpress\/?attachment_id=1495\" data-orig-file=\"https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2016\/02\/Screenshot-from-2016-02-02-115050.png?fit=758%2C688&amp;ssl=1\" data-orig-size=\"758,688\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Screenshot from 2016-02-02 11:50:50\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2016\/02\/Screenshot-from-2016-02-02-115050.png?fit=580%2C526&amp;ssl=1\" class=\"alignnone size-full wp-image-1495\" src=\"https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2016\/02\/Screenshot-from-2016-02-02-115050.png?resize=580%2C526\" alt=\"Screenshot from 2016-02-02 11:50:50\" width=\"580\" height=\"526\" srcset=\"https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2016\/02\/Screenshot-from-2016-02-02-115050.png?w=758&amp;ssl=1 758w, https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2016\/02\/Screenshot-from-2016-02-02-115050.png?resize=300%2C272&amp;ssl=1 300w\" sizes=\"auto, (max-width: 580px) 100vw, 580px\" \/><\/a><\/p>\n<p>You can test the output for the <a href=\"http:\/\/www.grodansparadis.com\/paris\/paris.html\">Paris module<\/a><\/p>\n<p><a href=\"http:\/\/eurosource.se\/xml2jsonp.php?url=paris_010.xml&amp;jsonp=callback\">here<\/a>.<\/p>\n<p>In this case the local MDF file is <a href=\"http:\/\/eurosource.se\/paris_010.xml\">paris_010.xml<\/a> and we request JSONP output using the function &#8220;callback&#8221;.<\/p>\n<p>If we skip the<\/p>\n<blockquote><p><em><strong>&amp;jsonp=callback<\/strong><\/em><\/p><\/blockquote>\n<p>we get pure <a href=\"http:\/\/eurosource.se\/xml2jsonp.php?url=paris_010.xml\">JSON output instead<\/a>.<\/p>\n<p>The script can be downloaded <a href=\"https:\/\/github.com\/grodansparadis\/vscp_php\/tree\/master\/utils\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To get a XML file in JavaScript can be difficult due to the same origin policy.\u00a0 CORS is on solution but using\u00a0 JSONP is a much simpler solution also because JavaScript kind of like the JSON format. The problem here for VSCP is that the MDF (Module Description File) is in XML format. We therefore [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[53,13],"tags":[],"class_list":["post-1492","post","type-post","status-publish","format-standard","hentry","category-howtos","category-vscp"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4raCZ-o4","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1492","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1492"}],"version-history":[{"count":2,"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1492\/revisions"}],"predecessor-version":[{"id":2946,"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1492\/revisions\/2946"}],"wp:attachment":[{"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1492"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1492"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1492"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}