Example of JSP + XML architecture website

xiaoxiao2021-03-06  94

XML (Scalable Markup Language) It can look like a certain W3C standard ?? There is no practical impact now, even if you can send it in the future, it is also a matter of time. But in fact, it has now been applied. So, don't wait until XML has been added to your favorite HTML editor to start using it. It now solves various internal problems and B2B system issues. In sparks.com, we use XML to standardize data representation between the Java objects to HTML data display. It is important to note that we have found that it can be more easily shared and manipulated as long as it is standardized with a very basic XML structure. In this process, we found a lot of effective ways to use XML. Let's introduce our current application. Standardization Before using XML, establish the XML data format that is different from the information you want to use. Generating Dynamic XML from generating HTML from the database is not fresh, but generating XML is very fresh. Here we introduce specific generating steps. Using XSL as a template language XSL (Extensible Style Sheet Language) is a good way to define XML data display formats. If you write a few static templates will be more efficient. Generating HTML XML plus XSL is equal to HTML. This seems wrong, but our HTML page seen by the user is actually the effect of XML and XSL. First, the ability to standardize XML comes from its flexibility. But unfortunately, it is sometimes too flexible, so that you will face a blank page and how to solve the problem. In any XML project, the first step is to create a standard data format. To do this, you have to make the following decisions: &&und determine data: Because there is no standard XML format, developers can freely develop their formats. However, if your format can only be identified by an application, you can only run this program to use this format. If you can also read your XML format, it will be more helpful. If an XML format is modified, the system using it may also need to be modified, so you should establish as completely as possible. Because most systems ignore labels they cannot identify, the safest way to change an XML format is to add tags instead of modifying tags. Click here to view the XML Data Format Instance in Sparks.com, we have viewed all product data required for different product demonstrations. Although not all pages use all data, we still develop a very complete XML data format suitable for all data. For example, our product details page displayed is more than the product browsing page. However, we still use the same data format in both cases because the XSL templates of each page are only using the fields they need. Whether to use DTD in Sparks.com, we use well-organized XML without using just correct XML because the former does not require DTD. DTD adds a processing layer between the user clicks and sees the page. We have found that this layer requires too much processing. Of course, when communicating with other companies in XML format, it is still very nice to use DTD. Because the DTD can guarantee the correct data structure when sending and receiving. Selecting the parsing engine now, there are several parsing engines that can be used. Select which one is almost entirely on your application needs. If you decide to use DTD, then this parsing engine must enable your XML to be verified by DTD. You can put the verification in a process, but you will affect performance. SAX and DOM are two basic parsing models. SAX is based on an event, so when XML is parsed, the event is sent to the engine. Next, the event is synchronized with the output file. The DOM parsing engine creates a hierarchical tree structure for dynamic XML data and XSL style sheets. With random access DOM tree, XML data can be provided, as determined by the XSL style table. The debate on the SAX model is mainly focused on the memory reduction of the DOM structure and speeds up the XSL style sheet parsing time.

However, we have found that many systems that use SAX have not fully utilized its capabilities. These systems use it to establish a DOM structure and send events through the DOM structure. In this way, DOM must be established from the style table before any XML processing, so performance will drop. Second, generate dynamic XML once an XML format is established, we need a way to dynamically transplant it from the database. Generating an XML document relatively simple because it only requires a system that can handle strings. We have established a system using Java Servlet, Enterprise JavaBean Server, JDBC, and RDBMS (relational database management systems). &&& (For additional information about XSL applications, see Using XSL as a template language.) Generating an Example of XML Creating an XML document string in Java can be divided into several methods and classes. The code that starts the XML generation process is placed in the EJB method. This instance will create a StringBuffer immediately to store the generated XML string. StringBuffer xml = new StringBuffer (); xml.append (XmlUtils.beginDocument ( "/ browse_find / browse.xsl", "browse", request)); xml.append (product.toXml ()); xml.append (XmlUtils. EndDocument ("browse"); out.print (xml.tostring ()); the three XML.Append () becomes the call to other methods. The first additional method of generating the file header calls the XMLUTILS class to generate XML file header. The code in our Java Servlet is as follows: Public static string begindocument (string stylesheet, string page) {stringbuffer XML = new stringbuffer (); xml.append ("") .append (""); XML.Append ("<") .append (page) .append (">"); return XML.toTOString ();} This code generates an XML file header. Tab to define this file as an XML file that supports version 1.0. The second line The code points to the location of the correct style sheet used to display the data. Finally, the item is an item-level tab ( in this instance). On the end of the file, only the tag needs to be turned off. After completing the product information, the control method will call the Java object to generate it. XML. In this example, the Product object is called. TheProduct object uses two ways to generate its XML representation. The first method toxml () creates a Product node by generating the and tags. Then it INTERNALXML () will be called, so you can provide product XM L The required content.

INTERNALXML () is a series of StringBuffer.Append () calls. StringBuffer is also converted into a string and returns to the control method. Public string toxml () {stringBuffer XML = new stringbuffer (""); XML.Append ("" XML.Append (""); return Xml.toString ();} public string INTERNALXML () {StringBuffer XML = New StringBuffer ("") .append (ProductTy) .append ("); XML.Append (") .append (idValue.trim ()) .append ("); XML. Append (") .append (idName.trim ()) .append (" "); XML.Append (" ") .append (" "); ?? Xml.Append "") .append (amount) .append (""); xml.append ("") .append (vendor) .append ("); XML.Append (" "); XML.Append (" "). Append (Pubdesc) .append (""); XML.Append ("") .append (vendesc) .append (";?? Return Xml.toTOString ();} Close the file, XMLUTILS.EndDocument () method is Call. This call turns off the XML tag (in this case), and finally completes the architectural XML file. The entire StringBuffer from the control method also converts into a string and returns a servlet that is processed to the initial HTTP request. Third, use XSL as Template Language In order to get HTML output, we combine the generated XML file and how the XSL template that controls how XML data is represented. Our XSL template consists of carefully organized XSL and HTML tags. Start building a template Our XSL template start section and below This code is similar. The first line of code is a required code, defined this file as an XSL style sheet .xmlns: XSL = Property Reference The XML namespace used in this file, and the version = property defines the version number of the namespace. At the end of the file, we turn off the label. The second line of code started by determines the mode of the XSL template . Match properties are required, here pointing to XML tags . In our system, the tag contains the tab, which allows the XSL template to access product information embedded within the tab. We must then close the tag at the end of the file. Next, let's take a look at the HTML of the organization. Since it will be processed by the XML parsing engine, it is necessary to meet all the rules of the organization's good XML. In essence, this means that all start tags must have a corresponding end tag. For example, it is usually not ended

tag, you must use to close.

In the main body of the template, there are many XSL tags that are used to provide logic for data representation. Explain two commonly used labels. The Choose Tag is similar to the beginning of the IF-THEN-ELSE structure in the traditional programming language. In XSL, the Choose tag represents the occurrence of the code to trigger the occurrence. Have the tag with assignment attribute back behind the Choose label. If the value is correct, the content between the start of will be used. If the value is incorrect, use The content between the start and end tags. The whole section ends with . In this example, the WHEN tab checks XML for the Quantity tab. If the quantity tag contains the value of the true error attribute The Quantity tab will display the list unit column below. If the value of the property is not true, the XSL will display the content between the Otherwise tag. In the following instance, if the error attribute is not true, what will not be displayed for-Each loop begins when the program encounters the label. This loop will end when the program encounters the label. Once this loop is running, this template will be applied each time the label appears.

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

New Post(0)