|
|
Development Ajax: Use XML in searches and answers
Today it is impossible to create a little significant programs without the reference{manipulation} to XML. Be you the developer of the Web-pages considering transition to XHTML, the Web-programmer developing JavaScript, the server programmer using descriptors of expansion and binding of the data, or the programmer investigating databases on basis XML, expanded language of a marking to you to not do without. Therefore it is no wonder, that XML it is considered one of root technologies which underlie Ajax.
However, such opinion reflects an insufficient choice of names for the root object used in Ajax-applications - XMLHttpRequest - than a technical reality more likely. In other words, the majority count XML root part Ajax as they assume, that object XMLHttpRequest really constantly uses XML. But it not so, and the reasons of it are considered{examined} in the first part of given clause{article}. Actually, you will see, that in the majority Ajax-applications XML in general seldom appears.
XML application in Ajax really finds, and XMLHttpRequest also it supposes. Certainly, nothing prevents you to send XML on the server. In earlier clauses{articles} of this series you used not ciphered the text and parameters of a name and values for the sent data, but the XML-format too is applicable. In this clause{article} you learn{find out}, how it to do{make}. And, that it is even more important, we shall talk about why you can apply XML to a format of your searches and why in many cases you should not apply it{him}.
XML: whether there Is he in general?
It is easy to make the assumption concerning Ajax-applications and use by them XML; and a name of technology (Ajax), and root object used by her{it} (XMLHttpRequest) specify use XML, and you will hear, that XML is constantly connected to Ajax-applications. However such perception{recognition} is incorrect, and if you really want to learn{find out}, with what you work at a spelling of asynchronous applications, you should know, what is it the perception{recognition} is incorrect - but it is more important to you to know why it incorrectly.
XMLHttpRequest: Unsuccessful names and HTTP
The worse, that can be to technology, its{her} this abusing up to such degree, that replacement of its{her} basic parts becomes impossible. It has taken place with XMLHttpRequest, a basic element used in Ajax-applications. By the name, he is designed for sending XML on HTTP-searches, or, probably, for creation of HTTP-searches in any XML-format. As though the name of object sounded, nevertheless his{its} real function consists in granting a way for your client - code (usually JavaScript on your Web-page) for sending HTTP-search. Only it, and no more that.
So, it would be well simple to change name XMLHttpRequest to something more exact, for example HttpRequest, or, it is possible, simple Request. However, millions developers now enter Ajax in the applications and as all of us know that years - if not decades are required - that the majority of users has passed to new versions of browsers, such as Internet Explorer 7.0 or Firefox 1.5, such transition is simply inexpedient. In result you remain with XMLHttpRequest, and developers only need to recognize, that the name is chosen unsuccessfully.
It is obvious, that one of the most known methods of transition to emergency operation (fallback methods) at the reference{manipulation} to a browser (it is especial on Windows) which does not support XMLHttpRequest, is application of Microsoft-object IFRAME. hardly probable similar on XML, HTTP, or even on search, is not it? It is obvious, that all these elements can be switched on, but it is important, that it was clear, that object XMLHttpRequest in the greater degree is intended for creation of searches without the reference{manipulation} to loading page, than for XML, or even HTTP.
Searches are done{made} with help HTTP, instead of XML
One more popular belief is the assumption, that XML anyhow is imperceptibly applied - the point of view which I and itself once adhered, to tell the truth! However, such point of view testifies to incorrect understanding of the given technology. When the user opens system of navigation (brouser) and requests Web-page from the server, something is typed{collected} like http://www.google.com or http://www.headfirstlabs.com. Even if it is not included http://, the browser will insert this part into the panel of the address of system. This first part - http:// is an obvious index on how there is a data transfer: through HTTP, the hypertext transfer protocol (Hypertext Transfer Protocol). When you write down a code on your Web-page to contact the server, whether there is a speech about application Ajax or about usual form POST or even about a hyperlink, you use HTTP.
HTTPS: still HTTP
Those from you who is less familiar with Web can to be surprised to such unified indexes of resources (URLs), as https://intranet.nextel.com. The report https is reliable report HTTP and simply applies more reliable form of report HTTP used by usual Web-searches. Therefore even with HTTPS all of you still simply apply HTTP, though and with some additional levels of protection against extraneous eyes.
In connection with that, that the Web-communications between browsers and servers occurs by means of HTTP, performance that XML somehow is imperceptibly used XMLHttpRequest as technology or means of data transfer does not correspond{meet} to the validity. Certainly it is possible to send XML in HTTP-search, but HTTP is very precisely determined standard which at any time without effort it is possible to refuse. If you intentionally do not use XML in your search or if the server does not send you the answer in XML in object XMLHttpRequest anything will be applied other as simple old HTTP. Therefore following time when somebody to you will say, " Yes, it is called XMLHttpRequest because here is imperceptibly applied XML ", simply smile and patiently explain to him, that represents HTTP, and explain, that while XML it is possible to send through HTTP, XML is a data format, instead of the transfer protocol of the data. Both of you will benefit by such explanation.
Application XML (actually)
At this stage I have told to you about all areas where XML it is not used in Ajax. But x in Ajax and XML in XMLHttpRequest nevertheless are very real, and you have some options for use XML in your Web-applications. In this section you learn{find out} about the basic options, and then you can familiarize in details with them in other sections of given clause{article}.
Options for XML
In your asynchronous applications you will find two basic applications XML:
* For departure of search from Web-page on the server in a XML-format
* For reception of search from the server on your Web-page in a XML-format
The first application - for departure of search in XML - demands, that you formed your search as XML, or applying for this purpose API, or simply connecting the text and then sending result on the server. This way the main considered{examined} problem{task} is construction of search according to rules XML so that he has been understood by the server. So, the basic attention is actually given a XML-format; you have data which you want to send, and you only should present them in XML-expression. Other part of given clause{article} is devoted to given application XML in your Ajax-applications.
The second application - for reception of search in XML - demands, that you have received search from the server and have taken the data from XML (besides with help API or more rough method). In this case your problem{task} will be extraction of the data received from the server from XML that it was possible to use them structurally. About it there will be a speech in following clause{article} of the given series where the detailed description of the given question will be given to you.
Strict caution
Before in details to consider{examine} use XML, it is necessary to make small caution: XML is large slow and bulky formaotm. As you will see in the subsequent sections and in following clause{article} of the given series, in this context there are thorough reasons for use XML, and some advantages XML before simple text searches and answers (it is especial for answers). However, XML almost always will borrow{occupy} more spaces and there will be more slowly, than a plain text because you add all tegi and semantics required for XML, in your messages.
If you want to write immediately fast application, such as the desktop application, XML can appear not the best starting point. If you will start with a plain text, and will find out special necessity for application XML, this other business; however, if you use XML from the very beginning, you almost for certain slow down response of your application. In most cases will faster send a plain text - with the help of pairs name / value (name/value), for example name=jennifer - than to transform the text in XML, as in an example:
<name> jennifer </name>
You only present all sites where application XML demands additional time: giving to the text of XML shell; sending of the additional information (notice, that I do not include here any accompanying elements, XML-heading, or something, that will be a part of more realistic search); parse XML by the server, creation of the answer, turning of the answer back in forrmat XML, and sending of it{him} back on your Web-page; and then parse of the answer by your page and, at last, use of it{him}. Therefore familiarize with that when to apply XML, but do not think, that your application in many situations will work faster; more likely, it will add flexibility about what we now and shall talk.
XML from the client to the server
Let's present application XML as a format for transfer of the data from the client on the server. First you will see as it to execute technically, and then give a few{a little;little bit} time for studying of expediency of application XML.

|