Application of XML in the development of BS architecture

zhaozj2021-02-11  187

Application of XML in the development of B / S architecture

Traditionally, we use JSP Bean to develop user interfaces, hereby introducing a way to use XML XSLT to replace JSP

motivation:

1. The JSP constructing page is too painful. The code embedding page leads to bloated pages, logic is complex, and it is difficult to edit.

2. Programmer and artist interface must be precisely defined. Complex nested outputs must construct complex display classes as an interface.

3. Debug JSP must wait until the end of the program is ended to see the effect.

3. The debugging JSP is extremely low, and a little small modification will cause the JSP recompilation.

New XML solution:

1. A servlet is unified management. Accept the URL request, map to the corresponding program bean.

2. The program bean generates only XML, and the corresponding XSL converted to HTML by the servlet unified.

benefit:

1. JDK1.4 has comes with XML API and XSLT, and supports XSLT 1.0 standard. IE6 also supports the same standard.

2. The Demo XML used before the development first creates the interface, and the programmer's output must conform to this format. The US is based on this format to make XSL. Interface visualize, clearly defined.

3. As long as the interface XML is defined, there is hardly need to be jointly debugged on both sides. Art uses interface XML and IE6 to see the effect directly.

4. Programmaker only guarantees whether the output XML is in line with the interface, intuitively doing textual comparisons.

5. A large number of page reusable parts can be easily abstract, in the XSL file, INCLUDE / IMPORT in the XSL file. Highly reuse, standardization.

6. Write XSL to use Template, clear structure, easy to modify, write the page to a wooden, no longer a layer of JSP.

7. For different terminal devices, different XSLs can be customized, which is convenient to support mobile phones, PDA ...

8. Using the support for XML in the program, such as SQL2000, you can directly generate XML results without complex programming.

harm:

1. Because XSLT conversion is to be performed, the server workload is slightly increased.

The following is a simple example of several key links: ============== x ======================== / ** * XML is String * XSL from the file Read * Directly Write Response * /// Import Javax.xml.Transform. *; // Import Javax.xml.transform.Stream. *;

StreamSource XML = New StreamSource (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 ============= promotes Unicode, solve multilingual issues. ================== xsl file sample =============

Considering: 1. You can put the XSLT conversion in IE, IE6 below to install MSXML3, limit too much to the client. The reaction is relatively slow. 3. Mobile phone, PDA and other devices cannot perform XSLT conversion, so XSLT conversion is appropriate to be placed on the server. 4. Because general submission is relatively simple, there is no XML processing, try as possible in the program Use less XML to avoid influencing speeds. 5. You can determine a specific parameter at the servlet, such as when there is an XML-View parameter, do not do XSLT conversion, direct output XML to your browser for program trial.

Description: 1. Here is just to use XSLT's function to solve the most headache interface and logical separation problems in website construction. Not based on XML-based content processing. 2. If you want to catch fashion, use XML to come to the whole armed armed, you can refer to Cocoon2, http: //xml.apache.org/cocoon/., please remember, cocoon

Not perfect, you will encounter the problem of garbled, speed, and document, but its idea is worth learning. 3. In Tomcat, there is useful XSLT conversion with Filter, you can refer to it. 4. Is there any good suggestion, please tell me: phpme@citiz.net (thank you spam :) QQ: 7461522

转载请注明原文地址:https://www.9cbs.com/read-5855.html

New Post(0)