Transfer of pairs name / value (name/value)
Approximately 90 % of Web-applications which you write, you finish in pairs name / value for departure on the server. For example, if the user types{collects} the name and the address in any form on the Web-page, you can obtain from the form about such data:
firstName=Larry
lastName=Gullahorn
street=9018 Heatherhorn Drive
city=Rowlett
state=Texas
zipCode=75080
If you used the usual text for transfer of these data on the server, you could apply a code as in Listing 1. (It similar on an example which I used in first clause{article} of this series. See. Resources.)
Listing 1. Sending of pairs name / value as the usual text
function callServer () {
// We receive the information on city and staff{state} from the Web-form
var firstName = document.getElementById ("firstName") .value;
var lastName = document.getElementById ("lastName") .value;
var street = document.getElementById ("street") .value;
var city = document.getElementById ("city") .value;
var state = document.getElementById ("state") .value;
var zipCode = document.getElementById ("zipCode") .value;
// We create URL for connection with
var url = "/scripts/saveAddress.php? firstName = " + escape (firstName) +
" *lastName = " + escape (lastName) + " *street = " + escape (street) +
" *city = " + escape (city) + " *state = " + escape (state) +
" *zipCode = " + escape (zipCode);
// We open connection with the server
xmlHttp.open ("GET", url, true);
// We establish{install} function for start of the server when it is executed
xmlHttp.onreadystatechange = confirmUpdate;
// We send the answer
xmlHttp.send (null);
}
Transformation of pairs name/value in XML
The first, that you need to make, if you want to use XML as a format of such data, it to create any basic XML-format for storage of these data. Obviously, your pairs name / value can be transformed all to XML-elements where the name of an element is a name of pair, and the maintenance{contents} of an element is value:
<firstName> Larry </firstName>
<lastName> Gullahorn </lastName>
<street> 9018 Heatherhorn Drive </street>
<city> Rowlett </city>
<state> Texas </state>
<zipCode> 75080 </zipCode>
Certainly, XML demands, that you had a root element, or if you simply work with a fragment of the document (a part of the XML-document), covering element. Therefore you can convert the above-stated XML-code in something similar:
<address>
<firstName> Larry </firstName>
<lastName> Gullahorn </lastName>
<street> 9018 Heatherhorn Drive </street>
<city> Rowlett </city>
<state> Texas </state>
<zipCode> 75080 </zipCode>
</address>
Now you are ready to create this structure in your Web-client, and to send it{him} on the server... Almost.
Data transfer of verbal type
Before you will be ready to start to send XML on a network, it is necessary for you to make sure, that the server and a script on which you send the data, really supposes XML. Now of you it can seem to much excessive and too obvious to give to this special znacheie, but it is a lot of programmers with the smaller experience assume, that if they send XML on a network, he will be correctly received and interpreted.
Actually, you should undertake two steps to make sure, that the data which you send in XML, will be received correctly:
1. Make sure, that a script on which you send XML, supposes XML as a data format.
2. Make sure, that the script will admit{allow} a special XML-format and structure in which you send the data.
Both steps, probably, will demand from you conversation with the person, so, strict caution! And it is serious, if it is important for you to be able to send the data, such as XML, the majority of authors of scripts to you will be obliged; therefore simply to find a script which will suppose XML, should not be difficult. However, you still need to make sure, that your format corresponds{meets} to that demands a script. For example, suppose, that the server accepts such data:
<profile>
<firstName> Larry </firstName>
<lastName> Gullahorn </lastName>
<street> 9018 Heatherhorn Drive </street>
<city> Rowlett </city>
<state> Texas </state>
<zip-code> 75080 </zip-code>
</profile>
Reminds above-stated XML, except for two moments:
1. XML, proceeding from the client, the address is placed inside an element, but the server expects, that the data will be placed in an element profile.
2. XML, proceeding from the client, uses an element zipCode whereas the server expects a zip-code in an element zip-code.
By and large, these really small moments represent distinction between the server accepting and processing your data, and the server suffering{bearing} failures and supplying your Web-page - and, probably, its{her} users - not clear erroneous soobhhniem. Therefore you should solve, that expects the server, and to reduce the data sent by you in this format. After that - and only after that - you are ready to engage in rather technical party{side} of process of transfer XML from the client on the server.

|