Application of XML in the development of B/s architecture

Source: Internet
Author: User
Tags interface xsl xsl file xslt client
xml| architecture Traditionally, we use Jsp+bean to develop the user interface, which introduces a way to use XML+XSLT to replace JSP

Motivation:

1. JSP Construction page is too painful. Code embedded page causes the page to be bloated, logic complex, difficult to edit.
2. The interface between programmers and artists must be defined precisely. Complex nested output must construct a complex display class as an interface.
3. Debug JSP must wait until the end of the front-end program to see the effect.
4. Debugging JSP efficiency is very low, a little bit of modification will cause JSP recompile. New XML Solution:

1. A servlet to do the unified management. Accept the URL request and map to the corresponding program bean.
2. The program bean produces only XML, which is unified by the servlet to convert the corresponding XSL to HTML.

Benefits:

1. JDK1.4 has its own XML APIs and XSLT, and supports the XSLT 1.0 standard. IE6 also supports the same standards.
2. Before the development of the first production interface with the demo XML, the programmer's output must conform to this format. The artist makes XSL from this format. Interface visualization, clearly defined.
3. As long as the interface XML is defined, there is little need for joint debugging on both sides. Using interface XML and IE6, the artist can see the effect directly.
4. Programmers just make sure that the output of the XML conforms to the interface, intuitive to do textual comparison.
5. A large number of reusable parts of the page can be easily abstracted and include/import in the XSL file. Highly reusable, standardized.
6. Write XSL can be a large number of template, structure clear, easy to modify, write pages into building blocks, no longer have the layer of JSP nesting.
7. For different terminal devices, you can customize different XSL, it is convenient to support the mobile phone, PDA ...
8. XML-enabled tools, such as sql2000, can be generated directly in the program without complex programming.

Harm:

1. Because of the XSLT transformation, the server workload is slightly increased. Here are a few simple examples of key links: XML transformations in ==============servlet ==========
/**
* XML is a string
* The XSL is read from the file
* Write directly to response
*/
Import javax.xml.transform.*;
Import javax.xml.transform.stream.*; Streamsource XML = new Streamsource (new StringReader (Xmlsource));
Streamsource xsl = new Streamsource (xslfilename); Response.setcontenttype ("text/html; Charset=utf-8 ");
Streamresult result = new Streamresult (Response.getwriter ()); Transformer trans = Transformerfactory.newinstance (). Newtransformer (XSL);
Trans.setoutputproperty ("Encoding", "UTF-8");
Trans.transform (XML, result); ================== interface XML File Sample =============
<?xml version= "1.0" encoding= "UTF-8"?
<?xml:stylesheet type= "text/xsl" href= "xxx.xsl"?
<PAGE>
<OUTPUT>
<INFO> promote Unicode to solve multiple language problems. </INFO>
</OUTPUT>
</PAGE> ==================xsl File Sample =============
<?xml version= "1.0" encoding= "UTF-8"?
<?xml:namespace prefix = xsl/><xsl:stylesheet xmlns:xsl= "http://www.w3.org/1999/XSL/Transform" version= "1.0"
<xsl:template match= "/" >

<p align=center>
<xsl:value-of select= "Page/output/info" > </xsl:value-of> </xsl:template>
</xsl:stylesheet> consider:

1. The XSLT transformation can be placed in IE, IE6 the following version to install MSXML3, too much to the client limit.
2. XSLT transformations on the client must be fully read into the xml+xsl, and the response is rather dull when the Internet is low or content is high.
3. Mobile phone, PDA and other devices can not be XSLT conversion, so XSLT conversion or on the server is more appropriate.
4. Because the general submission content is relatively simple, so did not adopt the XML processing, in the program also as far as possible uses the XML, avoids the influence speed.
5. You can judge specific parameters in the servlet, such as the discovery of xml-view parameters, do not do XSLT conversion, direct output XML to the browser, for program debugging. Description

1. This is only the use of XSLT to solve the Web site construction of the most headache interface and logic separation problem, not based on XML content processing.
2. If you want to follow the fashion, use XML to be armed, you can refer to Cocoon2, http://xml.apache.org/cocoon/. But remember, Cocoon is not perfect, you will encounter garbled, speed, documentation problems, but its thinking is indeed worth learning.
3. In tomcat, resin can be useful for the XSLT transformation of filter implementation.


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: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.