xml

XML (Extensible Markup Language) Vs. CSV (Comma Separated Values)

CSV is flat file with the data separated by commas. If we needn’t have to establish a relationship in the data presented in the CSV file, then we can go with storing the data as CSV and manipulate the content for display in the web pages.

XML allows hierarchical representation of data. Data in XML is more readable when it comes to presenting the data. Data can easily be validated with XSD and can be accessed with a couple of lines of code. Huge advantage of XML is its flexibility to establish relationship in data.

Share it onShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

PHP: How to receive the posted XML data?

Receive the posted XML data

In order to test the posted data, we can create a file creation steps to ensure that we receive the posted data via the $_POST array

<?php
/* 
  File name: postdata2.php
*/
    $xmlFile = "xmlFile.txt";
    $fh = fopen($xmlFile, 'w') or die("Cannot open file");
    fwrite($fh, $_POST["xmldata"]);
    fclose($fh);



?>
Share it onShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

PHP: How to post XML data using CURL?

During integration projects or during such similar situations you may have across a necessity to transfer XML data or plain text file across server locations.

Curl comes in handy during such scenarios. Following program is used to post XML data using Curl. In order for Curl to function, ensure that PHP settings has the curl module installed and that the libraries/dll libeay32, ssleay32 is installed in your server.

<?php
/* 
  File name: postdata.php
*/

$post_url = "http://localhost/demo/postdata2.php";
$xml_string = '<?xml version="1.0" encoding="UTF-8"?>
<books>
<book isbn="978-1594489587">
    <title>The Brief Wondrous Life of Oscar Wao</title>
    <publisher>Riverhead Hardcover </publisher>
    <amazon_price>14.97 </amazon_price>
    <author_firstname>Junot </author_firstname>
    <author_lastname>Diaz </author_lastname>
  </book>
<book isbn="999-1594489501">
    <title>A Thousand Splendid Suns </title>
    <publisher>Riverhead Hardcover </publisher>
    <amazon_price>14.27 </amazon_price>
    <author_firstname>Khaled </author_firstname>
    <author_lastname>Hosseini </author_lastname>
  </book>
</books>';


$ch = curl_init($post_url);

curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, "xmldata=".$xml_string);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);


$data = curl_exec($ch); 
// to get information on the curl resultset
$info = curl_getinfo($ch);

if(curl_errno($ch)){
    print curl_error($ch);
}

curl_close($ch);

?>
Share it onShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

PHP: CakePHP and XML

How to get XML content in cakePHP controller?

App::import('Xml');
$url = Server.Mappath("file/xml_file.xml");
$parsed_xml =& new XML($url);
Share it onShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn
Kurinchi Calendar
May 2017
M T W T F S S
« Apr    
1234567
891011121314
15161718192021
22232425262728
293031