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 (" Xml version =" 1.0 "?>") .append (" xml-stylesheet href =") .append (stylesheet) .append ("") .append ("type =" text / xsl "?>"); XML.Append ("<") .append (page) .append (">"); return XML.toTOString ();} This code generates an XML file header. XML> 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 (
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 (" tag, you must use p> to close.