Asynchronous JavaScript and XML data formats: XML SOAP HTML

Source: Internet
Author: User
Tags format soap require return web services client

Article Introduction: Ajax and Web service data formats: XML SOAP HTML.

When Ajax was created, it was meant to be: Asynchronous JavaScript and XML, asynchronous JavaScript and XML, which is generally the case:

    • First create a network service, such as a PHP page that can pass HTTP get/post parameters, and then return an XML-formatted response
    • Write some of the client's JS code. such as passing parameters and parsing XML. These calls are asynchronous, so the browser is not stuck in the process of waiting for data.
    • Work with the data in the XML, and then update the DOM node

The term Ajax is abused by developers and sales people. Today's word, which is supposed to be all caps, has become a new word, indicating the transfer of data without refreshing the page. The reasons are:

    • There is no need to use asynchronous methods
    • JavaScript is not necessarily used
    • Nor does it require XML

Ultimately, you have to transfer data between two devices regardless of the technology you use. This is the first part of the Rockux serial data format, and we'll talk about more data and features later.


In the beginning, XML is the best choice. Many languages have functions that support XML format parsing and serialization. Even if the language you're using doesn't support XML, he's actually a piece of text.

 1 2 3 4 5 6 7 8 9" (+) 
<?xml version= "1.0"?> <products> <book> <title>the principles of Beautiful Web design, 2nd edition</title> <url></url> <author>jason Beaird </author> <publisher>SitePoint</publisher> <price currency= "USD" >39.95</price> </ Book> <book> <title>jquery:novice to ninja</title> <url> Jquery1/</url> <author>earle Castledine & Craig sharkie</author> <publisher>sitepoint </publisher> <price currency= "USD" >29.95</price> </book> <book> <title>build Yo ur Own Database driven website</title> <url></url> < Author>kevin yank</author> <publisher>SitePoint</publisher> <price currency= "USD" >39.95 </price> </book> </products>

The benefits of XML are:

    • XML is readable and easy to understand.
    • Many languages have a good support for XML, and the key is JavaScript.
    • XML is more secure. Data must be extracted and parsed, so malicious data is effectively contained

However, XML also has its drawbacks:

    • There will never be an industry-approved format for XML. You need to adapt RSS and so on, the client's JavaScript must understand the only line
    • The data in XML format may be larger than the amount of data, and in asynchronous interaction, the smaller the data, the better.
    • There are some ambiguities in XML, should a data be a new element or a metadata attribute? As a property may be a small file, but this is not convenient to fit.
    • Parsing XML in JAVASCRITP is very difficult, XPath support is better, so you need to first convert
Grab value in <data> element
var xml = xhr.responsexml;
var nodes = xml.getelementsbytagname ("data");
var data =

Many developers think XML is dead, but I don't agree that XML may not be the best choice for Ajax right now, but you don't know how all Web services are deployed. And the popularity of XML is a great thing, don't ignore it.


SOAP is a standard format for data interchange. The detailed technical details document has hundreds of pages, and overall, SOAP relies on well-defined XML schemas.
Few developers in the world use SOAP (see enough). The beauty of soap is that the client's library can automatically convert the XML into native objects. Like what. NET developers can create a SOAP-based network service that clients do not need to do much. As developers, most of them use C #, and they don't care what remote machines use.
But the disadvantage of soap:

    • Soap even transcends the lengthy XML
    • It is still difficult to handle soap in JavaScript. Although SOAP libraries can assist with processing, there is still a lot of pressure on developers and browsers

Soap is still the choice between service-side communication, especially in the case of the same LAN. But not much in Ajax.


If you want to insert code into a page via an AJAX request, HTML is a simple format that does not require much processing. For example, suppose you need to display a shopping cart on every page. You already have such HTML code on the server side that you can return the same HTML code after you have purchased the opinion item.
Its benefits include:

    • Easy to use existing code to create a network service
    • No need for complex data processing on the client
    • HTML code can be quickly inserted into the page by innerHTML

But there are also disadvantages:

    • It's hard to isolate real valuable data. For example, if you want to display your cart in a different way elsewhere, you won't be able to use it.
    • The amount of data transferred is also larger, larger than XML
    • Inserting HTML has the risk of damaging existing pages
    • Security may be problematic, the corresponding data may have malicious code

In the following article in Rockux we will talk about:

    • Data formats for AJAX and Web services: JSON and JSONP
    • Data formats for AJAX and Web services: custom return format

Reprint Please specify:
Author: rockux–web Front end
From: Ajax and Web Service data formats: XML SOAP HTML

Related Article

Alibaba Cloud 10 Year Anniversary

With You, We are Shaping a Digital World, 2009-2019

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.