Kurinchi Blogger Scribbles …

Posts Tagged ‘xml’

Oct 05

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

Last updated: October 5th, 2012

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.

Oct 05

PHP: How to receive the posted XML data?

Last updated: October 5th, 2009

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

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

Oct 04

PHP: How to post XML data using CURL?

Last updated: October 5th, 2009

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.

  File name: postdata.php

$post_url = "http://localhost/demo/postdata2.php";
$xml_string = '<?xml version="1.0" encoding="UTF-8"?>
<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 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>

$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);

    print curl_error($ch);


Jun 01

PHP: CakePHP and XML

Last updated: June 1st, 2009

How to get XML content in cakePHP controller?

$url = Server.Mappath("file/xml_file.xml");
$parsed_xml =& new XML($url);

Valid HTML 4.01 Strict  Valid HTML 4.01 Strict