Greetings to all my readers!
Today we shall talk about very important technology not only for the world the Web, but also for programming as a whole. And we shall talk today about universality of the data and an interplatform exchange of the information. As you already, probably, have understood, for this purpose we shall use technologies WDDX.
But what is it such, - you ask.
WDDX has been developed by joint efforts of developers of company Alliery in 1998. Also she is called in this world for that only to unify the information, and to translate her{it} in one, format XML accessible to all platforms. And to say fairly at them it it has turned out. For the first time developers Alliery have introduced technology WDDX in the platform, namely ColdFusion. Eventually the given data format has typed{collected} popularity among developers modern veb'? (though not so strongly as it would be desirable). The given technology has been introduced into the majority of languages for web - programming. So modules are accessible to support WDDX for Perl, PHP, Python, ColdFusion and many others. Today we shall talk about very important technology not only for the world the Web, but also for programming as a whole. And we shall talk today about universality of the data and an interplatform exchange of the information. As you already, probably, have understood, for this purpose we shall use technologies WDDX.
Well, as given clause{article} is devoted WDDX for platform RNR about RNR now and there will be a speech.
In RNR the given technology is integrated by default, and is accessible in all versions since 3.x.
By and large technology WDDX not such and scale, also consists in several banal stages of data processing.
These stages:
* The data
* Serialization and transformation in WDDX a code
* Serializirovanie the data
* Deserializacija and transformation in an associative file
* The data
As you can see, from the data all began, and all has terminated in the data. Now let's talk more in detail about each of stages.
Well, we admit{allow} at us there is some variable of any type, and we need to transfer her{it} in WDDX a format, for the further transformation. For this purpose we make serialization, and that is translation of the data in WDDX. However we pass not only the data and the name of the variable associated with them, but also type of the associated variable, as what for to us the ordinary data.
At present WDDX supports the majority of types of the data accessible on different platforms (numbers, lines, structures, files).
Well, that to you was more understandable, we now shall write a small example on serialization of the data to show structure WDDX of the data on an example.
<? php
$array=array ('dasa', 'fgs', 312ew ');
$integer=312;
$string ='fgasdfasf ';
$pack=wddx_packet_start (' First WDDX package ');
wddx_add_vars ($pack, 'array', 'integer', 'string', 'float');
$serialized_data=wddx_packet_end ($pack);
print htmlspecialchars ($serialized_data);
?>
That give under the order. First we declare a different sort variables, that serializirovat` them in WDDX a format. After that we create "starting" package WDDX.
By the way, you can leave some any comment as parameter of function wddx_packet_start (). The given text will be added in special XML-teg with indifikatorom <comment>.
As a whole he does not carry any practical advantage{benefit} besides that explains applicability of the data in given WDDX a package.
After we have created a package, we have opportunity to add in him{it} the new data. For this purpose we cause function wddx_add_vars. Which the first argument accepts the identifier of a package, and after n-? quantity{amount} of arguments of line type which will carry the name of variables in RNR environment. The same function makes process of serialization of the data.
Now we simply cause function wddx_packet_end to which we pass a resource of a package, and the returned result we appropriate{give} a variable $serialized_data. Now at us is ready WDDX a code which can be displayed.
For his{its} display we use to it{him} function htmlspecialchars as a browser it will not be correct to display "tegovye" the data.
, as you can see anything arkhislozhno (grandfather Lenin has as though said) in it no.
These data now can be transformed successfully to the data on other platform, and to continue job with them. And at once and pojavljaet`sja a question how them to transform back?
And it is very simple, for this purpose there is a procedure deserializacii. Deserializacija it just process return serializations, namely translation of the data into this or that platform, as an associative file where an index will be the name of a variable, and value its{her} contents. For deserializacii in RNR function wddx_deserialize or its{her} prototype wddx_unserialize the matter is that function wddx_unserialize is accessible only in late versions of language RNR and consequently we in given clause{article} shall use function wddx_deserialize serves.
Well, give also it we shall test, for presentation:
<?
$array=array ('dasa', 'fgs', 312ew ');
$integer=312;
$string ='fgasdfasf ';
$pack=wddx_packet_start (' First WDDX package ');
wddx_add_vars ($pack, 'array', 'integer', 'string');
$serialized_data=wddx_packet_end ($pack);
// I shall remove initial variables to show you, that they is valid
// peresozdadut`sja
unset ($array, $integer, $float, $string);
$deserialized_data=wddx_deserialize ($serialized_data);
foreach ($deserialized_data as $k => $ v) {
$$ k = $ v;
}
print $integer. ';'. $ array. ';'. $ string;
?>
, as you can see, all successfully works.
First we delete variables (do not forget are not necessarily), and the ambassador we cause function wddx_deserialize and we pass her serializirovanye the data as argument, and result of its{her} performance we appropriate{give} a variable $deserialized_data. But in fact the file and consequently we need to translate it{him} in a format of usual variables is not necessary for us. For this purpose we do{make} the elementary perebor and recollecting subtleties RNR we appropriate{give} peremenno which name will be value of a variable $k, value of a variable $v so we completely restore all variables.
As you can see, process of job with technology WDDX is rather simple, however for full mastering a material, we shall create the small project, in conformity with which we all over again shall generate the WDDX-compatible data in ColdFusion environment about the data, say, stock exchanges of actions{shares}, further our problem{task} will translate the data in RNR environment, for their further processing.
Well, we shall start.
Code on PHP
<html>
<head>
<title> the Stock exchange of actions{shares} </title>
<meta http-eqiv ='Content-Type ' Content ='text/html; charset=windows-1251 '>
<meta name ='Author ' Content ='LoRd aka K.Karpenko '>
</head>
<body>
<? php
if (isset ($ _POST ['add'])) {
$title = $ _ POST ['title'];
$cost = $ _ POST ['cost'];
$saldo = $ _ POST ['saldo'];
$package=wddx_packet_start (' Share Information System ');
wddx_add_vars ($package, 'title', 'cost', 'saldo');
$serialized_data=wddx_packet_end ($package);
$f=fopen ('data.xml', ' w + ');
flock ($f, LOCK_EX);
fwrite ($f, $serialized_data);
flock ($f, LOCK_UN);
fclose ($f);
print " the Data are successfully added! ";
}
?>
<form action = " method ='post '>
The name of actions{shares}: <input type ='text ' name ='title '> <br>
Stoimost`1000 Actions{Shares}: <input type ='text ' name ='cost '> <br>
Exchange balance: <input type ='text ' name ='saldo '>
<input type ='submit ' name ='add ' value ='Dobavit` '>
</form>
</body>
</html>
You most likely have already understood a principle. The data received from the form we serializiruem in format WDDX, and then write them to a certain file data.xml, for the subsequent processing in ColdFusion environment which will process the data of a file.
Code on CFML
<html>
<head>
<title> Cost of actions{shares} at a stock exchange </title>
</head>
<body>
<cflock name ='Block ' type ='ReadOnly ' timeout = '60'>
<cffile action ='read ' file ='data.xml ' variable ='wddx_data '>
</cflock>
<cfwddx action ='wddx2cfml ' input = ' * wddx_data * ' output ='shares_cost '>
The data on a stock exchange: <br>
<cfoutput>
*shares_cost *
</cfotput>
</body>
</html>
That's all, on it we finish consideration of technology of interplatform exchange WDDX. If at you questions on the given subject will appear or you will face problems during use of technology, necessarily write, and we together shall solve the appeared problems.
|