Take a piece of translation a month ago, when you have time, you will slowly make up
1. The sky from XML is blown up
There is another time, everyone is talking about XML, all application servers support XML, all B2B applications join XML, Web Services use XML, even databases are also using XML. But there are not many people really consider why it is useful in their own app when using XML.
When I said XML, we will think of HTML, but how XML and HTML distinguish between essentially. First of all, we can explain this problem: HTML is a kind of how to tell the browser to draw things in Windows, such as drawing a picture here, which draws a word, here there is another color. He didn't tell the browser more things, let us see an example:
Hello, I am an HTML page P>
Rainforest program P>
body>
html>
This html tells the browser:
2 I am an HTML page
2 I have a body
2 I have a paragraph
2 Contains the sentence "Hello, I am an HTML page" and "Programming of the Rainforest"
But if you are an African, you don't understand Chinese, then please answer this question: Who wrote this page?
You can't make any semantic analysis of the above programs, you only know that you can draw some things on the screen. In other words, your semantic analysis capabilities are limited to how to draw. But if you receive the following page:
dsfdfdf param>
content>
page>
Announce the question above, you can get answers easily: SDFDSF. Therefore, XML makes you have the ability to semantically analyze. This is worth "touting" for a computer.
But let's take a look at the next XML document.
fgsdfg>
dsfds>
The above is still an XML document, you can still analyze it, but you will not get any so-called "correct" results, because you want to explain it. So, we see that there is only XML, then it is not as strong as we touched.
Now, if you have some summary, right, actually only XML, it can do it yourself, it is a language, tell you what it described, but if you don't analyze it, then it's a little for you Nothing. So we have to solve and use other problems that use it to introduce some other help.
But we can use XML with semantic features and define our data. How to make everyone can read it does not generate "misunderstanding", we introduced DTD. Now we can use it, and how to use it is another problem, such as using HTML to tell the display how to print it, use XML? Only it certainly doesn't work, why don't we convert it into HTML? So we introduced some techniques that convert XML into HTML. That is, XSL. Now we can print the XML on the display. Then think about it, since the XML can be converted into HTML to be understood in the monitor, it can, of course, can be converted into the format that can be understood by other devices (this is of course the HTML cannot be done). So we found that although there is only one XML data file, it can be easily understood by all other devices. This is the powerful function of XML!
Let's take a look, XML becomes HTML process:
XML Page --- (Transformation) -> HTML PAGE
^
|
Transformation Rules
This process You have to write a program with Transformation Rules, then run your program, read your XML data, and generate HTML format. However, next time, I have to ask this book through my mobile phone, then it is going to convert to WAP, and if I want to print these things through PDF, I have to write a PDF conversion program, and then read my XML data,. . . So, this is a very cumbersome thing. Is there anything else to solve this problem for me? That is Cocoon.
1. Separate your attention
Cocoon is not the first product that transforms XML on the server. In fact, there is such a product very early before, and COCOON adds those functions?
So let us introduce Cocoon's most important innovation. Separation of Concerns (SOC). Separate your attention. Why is you going to separate your attention.
This world is not owned by everyone. In some ways you are an expert, but in another, you may be mentally mentally. So in your development team, you don't need to care about all things, but should be more concerned about your expertise. So your team can play the greatest effect. So you will separate your attention from those places.
Cocoon XML Publishing Framework is to separate you from some things, so that you will focus on some things.
Let's take a look at the Cocoon Framework:
It separates logic, content, and represents three parties.
Why do you want this? Because of the programmer, the art has very different skills and work habits. If you want to think about how to hide some part of the interface, the programmer will think about how to make the interface more perfect. That will be very funny and waste of manpower.
Under the Cocoon framework, the programmer only considers how to write logic, how to generate content, and the art only needs to consider how to show these content.
2. Cocoon's basic mechanism
The Cocoon Basic Mechanism is to solve the problem by handling an XML document, and it has a mechanism for automatically handling an XML document. It introduces a concept "pipeline" under UNIX. Figure:
Pipeline is like a pipeline, which has different components above. The opening and end of the pipe is installed on the Matcher Matcher and the Serializer Series, and some Transformer converters are installed in the middle to perform data transformation. The processing of documents is implemented in the pipeline through different components from the SAX event stream in different components. Let us look at his basic process:
2 Depart from Matcher (Matcher), issue a request
2 Generate data streams from the XML document 2 via the Generator (generator) Transformation XML document through the Transformer (Transformation)
2 Aggregation (aggregate) to aggregate XML documentation
2 Finally, the XML document is serially through the Serializer (Series)
PIPELINE processing flowchart:
Cocoon's processing is from HTTP Request. In the end, there is an http response. Let us look at the sequence diagram of the PIPELINE process, will be more understandable:
Let's take a look at the Cocoon you a very important technology: XSP (XML Server Page).
XSP is a technique for dynamically generating XML data. He itself is also an XML document, but to define this XML document according to the following requirements:
2 The root element of the document is
2
2 Must define the namespace of XSP Namespace
2 In order to make XSP more useful. There is at least one
See an example of XSP:
XML Version = "1.0" encoding = "UTF-8"?>
XMLns: Xsp = "http://apache.org/xsp" XMLns: xsp-formval = "http://apache.org/xsp/form-validator/2.0" XMLns: Xsp-request = "http://apache.org/xsp/request/2.0" XMLns: ESQL = "http://apache.org/cocoon/sql/v2" XMLns: Xsp-session = "http://apache.org/xsp/session/2.0" Create-session = "yes"> IF ( { } Else IF ( { } IF ( { Else IF ( { } xsp: logic> tips> xsp: Page> Since Cocoon is starting from the processing HTTP request, we can use some HTTP objects in XSP as in JSP. Such as REQUEST, RESPONSE, SESSION, etc. We can add a Java code by adding the Java code to add the Java code in the XSP, adding a Java code to add <%%> to the JSP. Then via