The best way to learn XML is to start with simple development, practice boldly, and proceed step by step. The beauty of XML can only be deeply understood during the development process. It is impossible to learn XML without development. Therefore, when learning XML, you should first establish an XML development environment. Let me introduce to you how to establish a Java-based XML development environment. Since I don't have access to Linux right now, all examples are done on Windows. However, all the software introduced here can be used on Linux and Windows, and the usage is similar. Moreover, except for Sun's JRE, they are all open source software, and anyone can use them for any purpose, or even redistribute them for commercial purposes. JRE is also free to download and use, but there is no source code. If you have experience using these software on Linux, I hope you can contribute it to everyone.
Setting up an XML development environment requires the following steps:
1. Install Java runtime environment
2. Install a Java compiler.
3. Install a JSP Container.
4. Install a taglib that supports XSLT.
5. Install an XML Parser.
6. Install a browser that supports XSLT.
7. Install an XML file editor (optional).
Step 1. Install Java runtime environment
It is recommended to use Sun's JRE 1.3, which can be downloaded from here:
http://java.sun.com/j2se/1.3/jre/download-windows.html
NOTE: Not JDK 1.3, all we need is JRE 1.3
After downloading JRE 1.3, run the installation program, assuming it is installed under C:JRE1.3. Then you need to set three environment variables.
JAVA_HOME=C:JRE1.3
CLASSPATH=.;C:JRE1.3librt.jar
PATH=%PATH%;C:JRE1.3bin
If it is Windows 95/98/me, put the environment variable settings in Autoexec.bat, then restart the machine. For Windows NT/2000, just set them in "My Computer/Properties".
Step 2: Install a Java compiler.
It is recommended to use IBM's jikes, an efficient open source Java compiler. jikes homepage is at
http://oss.software.ibm.com/developerworks/opensource/jikes/
The latest version is 1.1.3, which can be downloaded from here:
/u/info_img/2009-07/07/jikes-1_13-mingw-win32.zip
After downloading, unzip it to get a jikes.exe and place it in any directory in the PATH environment variable, such as C:JRE1.3bin
Edit a simple hello world program and try it:
// hello.java
public class hello {
public static void main(String [] args) {
System.out.print("hello, world!n");
}
}
then compile
jikes hello.java
If hello.class is generated, it can be used.
Step 3. Install a JSP Container.
It is recommended to use Jakarta's Tomcat 3.2.1. Tomcat 3.2.1 can be downloaded from here:
http://jakarta.apache.org/builds/jakarta-tomcat/release/v3.2.1/bin/
You need to download the jakarta-tomcat-3.2.1.zip file. If you are installing under Windows NT/2000, there is also jk_nt_service.zip in the win32/i386 directory.
After downloading, unzip it, assuming it is placed under C:tomcat and then you need to set an environment variable.
TOMCAT=C:tomcat
In order to make Tomcat use jikes, you need to do a little hack, as follows:
Add parser.jar, jaxp.jar, and webserver.jar in tomcat's lib directory to the environment variable CLASSPATH to make it effective and then perform the following steps:
cd tomcatsrcorgapachetomcatcontext
Edit the file WebXmlReader.java and change
// sw.addInitParam("jspCompilerPlugin", "org.apache.jasper.compiler.JikesJavaCompiler");
Remove the comment before
then compile
jikesWebXmlReader.java
Create a temporary directory and use the jar tool (available from the JDK) to decompress webserver.jar in Tomcat's lib directory.
mkdir t
cdt
jar xvf ..webserver.jar
Replace WebXmlReader*.class under orgapachetomcatcontext with the WebXmlReader*.class just compiled and generated
Then repackage:
jar cf webserver.jar .
Replace Tomcat's webserver.jar with the new webserver.jar
Edit web.xml in Tomcat's conf directory and change
<!-- uncomment the following to use Jikes for JSP compilation
<init-param>
<param-name>jspCompilerPlugin</param-name>
<param-value>org.apache.jasper.compiler.JikesJavaCompiler</param-value>
</init-param>
-->
Remove external comments.
Edit tomcat.bat in Tomcat's bin directory and replace all tools.jar with rt.jar
Start tomcat and run startup.bat in the bin directory.
Use a browser to do a test and visit
http://localhost:8080
If both the JSP and Servlet examples compile and run, Tomcat will work.
Stop Tomcat using shutdown.bat
Under Windows NT/2000, tomcat can be installed as a service as follows:
Copy wrapper.properties from Tomcat's conf directory and edit it. Change two of the variables
wrapper.tomcat_home
wrapper.java_home
Set the installation paths of TOMCAT and JRE respectively, and replace all tools.jar with rt.jar.
then run
jk_nt_service -I Tomcat wrapper.properties
Where Tomcat is the name of the service we installed.
Enter the control panel and start the Tomcat service. After the Tomcat service is installed, it is set to start manually. You can modify the properties of the Tomcat service to make it start automatically.
Delete Tomcat service with:
jk_nt_service -R Tomcat
Step 4. Install a taglib that supports XSLT.
It is recommended to use XSL Taglib in Jakarta Taglibs for XSLT
Its page is at http://jakarta.apache.org/taglibs/doc/xsl-doc/intro.html
Download the XSL Taglib snapshot from this page. You can also download all Jakarta Taglibs. Jakarta Taglibs have a wide range, but here we are only going to use the XSL Taglib.
After downloading, unzip it, copy the two files xsl-examples.war and xsl-doc.war to Tomcat's webapps directory, and then restart Tomcat. Access using a browser
http://localhost:8080/xsl-examples/
Run Apply.jsp in the page. If there are no errors and a page with many tables is displayed, XSL Taglib can be used.
The XSL Taglib document is also installed, in
http://localhost:8080/xsl-doc/
You can start from this example and start writing your own XML handler step by step. For example, you can add a new Context in Tomcat's server.xml
<Context path="/jspxml"
docBase="path-to-your-work-directory"
crossContext="false"
debug="0"
reloadable="true" >
</Context>
The path-to-your-work-directory is your development directory. Copy the contents of Tomcat's webapps/xsl-examples directory intact to your development directory, and use this program as a reference to start writing your own XML processing program.
For information on how to use JSP for XML development, you can refer to Sun's whitepaper at: http://java.sun.com/products/jsp/pdf/JSPXML.pdf
This is basically the method I told you above.
Step 5. Install an XML Parser.
After completing steps 3 and 4, you already have two available XML Parsers, namely Sun's JAXP used by Tomcat itself and xml.apache.org's Xerces used by XSL Taglib. JAXP includes two files, parser.jar and jaxp.jar, and Xerces has only one file, xerces.jar. These files can be found in the Tomcat directory.
It is recommended to use the Xerecs XML Parser because it currently supports XML Schema and it is open source software. But this is purely a matter of personal preference, and Sun's XML Parser is also excellent. After deciding which XML Parser to use, add its file to CLASSPATH. But don't use both XML Parsers at the same time. After CLASSPATH takes effect, you can use JDOM and SAX APIs to process XML files in your Java program.
Examples of applicable situations and usage of JDOM and SAX can be found here: http://developerlife.com
Step 6. Install a browser that supports XSLT.
This step is not necessary, because we can now use XSL Taglib on the server side to convert the XML file into HTML format and send it to the Browser, so in fact you can use any browser you like. But installing a browser that supports XSLT can facilitate our learning. Although we need to do XSLT on the server side now, when browsers that support XSLT become popular in the future, we can even skip this step and just send the XML and XSL files directly to the browser. This can greatly reduce the burden on the server side, because doing XSLT is not an easy task.
Mozilla 0.8 is recommended. At this point, you may want to ask again, why not use IE 4/5? Can't IE 4/5 also do XSLT? Aside from personal preference, I can cite 3 reasons to use Mozilla:
First of all, the XSLT version supported by Mozilla is newer than IE 4/5. The XSLT supported by IE 4/5 is not an official version, but a draft. That is: http://www.w3.org/TR/WD-xsl, and the XSLT supported by Mozilla is the official version of XSLT. Namely: http://www.w3.org/1999/XSL/Transform.
Secondly, XML applications in Mozilla include not only XSLT, but also RDF, XUL, SVG, MathML, etc., so Mozilla's support for XML exceeds IE 4/5 in breadth and depth.
The author of the third XML FAQ highly praises Mozilla and believes that Mozilla's support for XML is much better than IE 4/5 in terms of robustness.
OK, having said all that, let’s turn to the topic, how to make Mozilla 0.8 support XSLT?
First, download Mozilla 0.8 from here: http://www.mozilla.org/releases/
The latest version is version 0.8.1, but this version cannot run after installing a module that supports XSLT, so currently we can only use the older but slower version 0.8.
If you no longer want other features such as SVG/MathML, the most convenient way is to install it using the prepared .exe file.
After installation, start Mozilla and visit this page: http://www.mozilla.org/projects/xslt/
There is an Install button on the page. Click this button to install the TransformMiiX module that implements the XSLT function.
Restart Mozilla and visit the page mentioned above. Click on the link to the simple example above. If you see the same results as when you click the look like link, then your Mozilla already supports XSLT.
Regarding how to configure Mozilla 0.8 to support Java Plug-in, please refer to another post I posted on the XML version: XML client solution based on Mozilla. I won’t go into details here.
Step 7. Install an XML file editor.
This step is even less necessary. Have you heard that people still use vi to create HTML pages? I have seen such a person, and that is Teacher Yu Mingjian. There is a striking sentence on Teacher Yu’s personal homepage: Just vim it! In fact, you can use any editor you like to edit XML files, but for the convenience of friends who are accustomed to using WYSIWYG editors, I still recommend a few comparisons Good XML editor:
1. XML Spy: A fully functional XML editor, a trial version is available for download.
http://www.xmlspy.com/
2. EditML Pro: Another XML editor with more complete functions.
http://www.editml.com
3. PSGML for Emacs: Emacs, I don’t need to say anything, right?
http://www.lysator.liu.se/projects/about_psgml.html
Here is just to introduce some other knowledge as the icing on the cake. Using this knowledge, we can build a more powerful development environment.
Step 8. Install a better JSP Framework
It is recommended to use Struts. Struts is a sub-project of the Jakarta project, which aims to develop a JSP Framework based on the MVC design pattern. Developing within the Struts framework can effectively separate the presentation layer and implementation layer of Web applications and improve code reusability. Development based on the MVC design pattern is the so-called Model 2 development pattern. The project is currently nearing completion, and the latest version is 1.0-beta-1.
For information about what the MVC design pattern is, you can refer to the book "Design Patterns" from the Machinery Industry Press. Regarding the usage of Struts, you can refer to my translation of the "Struts User Guide" in the article collection: http://www.linuxforum.net/doc/strutsuserguide.html
Download Jakarta Struts from here:
http://jakarta.apache.org/builds/jakarta-struts/release/v1.0-b1/
You need to download the jakarta-struts-1.0-b1.zip file.
Unzip it, then copy the two files struts-example.war and struts-documentation.war to Tomcat's webapps directory, and then restart Tomcat. Access using a browser
http://localhost:8080/struts-example/
Run the MailReader program on the page. If it can be registered correctly, it can be used.
The Struts documentation is also installed.
http://localhost:8080/struts-documentation/
For information on how to use Struts in your own development directory, please refer to the documentation provided with Struts. There are some discussions about Struts in the Java version, which can be found using the search function of the forum.
Step 9. Establishing a connection with Apache has been talked about for a long time. Let me introduce the simplest method, using mod_jk to establish a connection with Apache.
Assuming you have Apache installed, download mod_jk from here:
http://jakarta.apache.org/builds/jakarta-tomcat/release/v3.2.1/bin/win32/i386/
You need to download the mod_jk.zip file.
Unzip it to get a mod_jk.dll and copy it to the modules directory under the Apache installation directory.
Modify Apache's configuration file httpd.conf and add the following two lines:
Include C:/tomcat/conf/mod_jk.conf-auto
JkMount /*.do ajp12
Among them, "C:/tomcat" is the installation directory of Tomcat.
Add index.jsp to DirectoryIndex, that is:
DirectoryIndex index.html index.jsp
If there is a comment before ServerName, open the comment before ServerName and set it to localhost, that is:
ServerName localhost
Restart Apache and visit this page:
http://localhost/examples/
If the jsp and servlet directories can be listed, the connection between Tomcat and Apache is established.
OK, after saying so much, it is actually just sorting out the housekeeping. Now that the housekeeping is sorted, we can start XML development. :-)