The best way to learn XML is to start with simple development, boldly practice, and step by step. The beauty of XML can only be deeply understood during the development process. Without development, you cannot learn XML well. Therefore, when learning XML, you should first establish an XML development environment. I will introduce to you how to establish a Java-based XML development environment. Because I can't use Linux now, all the examples are done on Windows. However, all the software introduced here can be used on Linux and Windows, and the usage is similar. And except Sun's JRE, there are open source software, which anyone can use for any purpose, or even reissue for commercial purposes. JRE can also be downloaded and used for free, but there is no source code. If you have experience using these software on Linux, I hope to contribute to everyone.
Establishing 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 an XSLT-enabled browser.
7. Install an editor for XML file (optional).
Step 1. Install Java runtime environment
It is recommended to use Sun's JRE 1.3, which can be downloaded from here:
/j2se/1.3/jre/
Note: Not JDK 1.3, all we need is JRE 1.3
After downloading JRE 1.3, run the installer, assuming it is installed under C:\JRE1.3. Then three environment variables need to be set.
JAVA_HOME=C:\JRE1.3
CLASSPATH=.;C:\JRE1.3\lib\
PATH=%PATH%;C:\JRE1.3\bin
If it is Windows 95/98/me, put the settings of the environment variable in , and then restart the machine, and set Windows NT/2000 in "My Computer/Properties".
Step 2: Install a Java compiler.
It is recommended to use IBM's jikes, a Java compiler with efficient open source. Jikes' homepage is
/developerworks/opensource/jikes/
The latest version is 1.1.3, which can be downloaded from here:
/pub/jikes/jikes-1_13
After downloading, unzip it and get a directory in any PATH environment variable, such as C:\JRE1.3\bin
Try editing a simple hello world program:
//
public class hello {
public static void main(String [] args) {
("hello, world!\n");
}
}
Then compile
jikes
If generated, it can be used.
Step 3. Install a JSP Container.
Jakarta's Tomcat 3.2.1 is recommended. Tomcat 3.2.1 can be downloaded from here:
/builds/jakarta-tomcat/release/v3.2.1/bin/
You need to download jakarta-tomcat-3.2.
If you are installing under Windows NT/2000, there is also jk_nt_service.zip in the win32/i386 directory.
Decompress after downloading, assuming it is placed under C:\tomcat
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 the environment variable CLASSPATH in the lib directory of tomcat, and perform the following steps after it takes effect:
cd \tomcat\src\org\apache\tomcat\context
Edit the file and
// ("jspCompilerPlugin", "");
Remove the previous comment
Then compile
jikes
Create a temporary directory and use the jar tool (available from the JDK) to unzip the Tomcat lib directory
mkdir t
cd t
jar xvf ..\
Replace WebXmlReader*.class under org\apache\tomcat\context with the WebXmlReader*.class that was just compiled and generated
Then repackage:
jar cf .
Replace Tomcat's
Edit Tomcat's conf directory to
<!-- uncomment the following to use Jikes for JSP compilation
<init-param>
<param-name>jspCompilerPlugin</param-name>
<param-value></param-value>
</init-param>
-->
Remove the comments from the outside.
Edit Tomcat's bin directory and replace all
Start tomcat and run bin directory.
Use the browser to do a test and access
http://localhost:8080
If both JSP and Servlet examples can be compiled and run, Tomcat will be used.
Stop Tomcat
Under Windows NT/2000, tomcat can be installed as a service, as follows:
Copy and edit the Tomcat conf directory. Put two of these variables
wrapper.tomcat_home
wrapper.java_home
Set the installation paths to TOMCAT and JRE respectively, and replace all with .
Then run
jk_nt_service -I Tomcat
Where Tomcat is the name of the service we installed.
Go to Control Panel to start Tomcat service. After the Tomcat service is installed, it is set to manually start. You can modify the properties of the Tomcat service to make it automatically start.
Delete Tomcat service with:
jk_nt_service -R Tomcat
Step 4. Install a taglib that supports XSLT.
Recommended XSL Taglib for XSLT in Jakarta Taglibs
Its page is in /taglibs/doc/xsl-doc/
Download snapshot of XSL Taglib from this page. You can also download all Jakarta Taglibs. Jakarta Taglibs has a wide range, but what we want to use here is the XSL Taglibs.
After downloading, unzip, copy the two files and the files into the webapps directory of Tomcat, and then restart Tomcat. Access using a browser
http://localhost:8080/xsl-examples/
If there is no error in the running page, it displays a page with many tables, and XSL Taglib can be used.
The XSL Taglib documentation is also installed,
http://localhost:8080/xsl-doc/
You can start writing your own XML handler step by step based on this example. For example, you can add a new Context to Tomcat
<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 in Tomcat's webapps/xsl-examples directory to your development directory intact, and start writing your own XML handler with this program as a reference.
Regarding how to use JSP for XML development, please refer to Sun's whitepaper, at: /products/jsp/pdf/
What I'm talking about is basically the method I told you above.
Step 5. Install an XML Parser.
After completing Step 3 and Step 4, you already have two available XML Parsers, namely Sun's JAXP and Xerces used by XSL Taglib. JAXP includes two files and , Xerces has only one file , these files can be found in the Tomcat directory.
It is recommended to use Xerecs XML Parser because it can currently support XML Schema and it is open source software. But it's all out of personal preference, Sun's XML Parser is also excellent. Decide which XML Parser to use and add its file to CLASSPATH. But don't use two XML Parsers at the same time. After CLASSPATH takes effect, you can use the JDOM and SAX APIs to process XML files in your Java program.
Examples of the occasions and usages of JDOM and SAX can be found here:
Step 6. Install an XSLT-enabled browser.
This step is not necessary, because we can now convert XML files to HTML format and send them to Browser using XSL Taglib on the Server side, so you can actually 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, after the browsers that support XSLT become popular in the future, we can even save this step and just send the XML and XSL files 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. Speaking of this, you may be asking again, why not use IE 4/5? IE 4/5 can also do XSLT? In addition to personal preferences, I can give you 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:///TR/WD-xsl , and the XSLT supported by Mozilla is the official version of XSLT. That is: http:///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 terms of breadth and depth.
The author of the third XML FAQ highly praised Mozilla, believing that Mozilla's support for XML is much better than IE 4/5 in terms of robustness.
OK, after saying so much, now turn to the topic, how to make Mozilla 0.8 support XSLT?
First, download Mozilla 0.8 from here: /releases/
The latest one is version 0.8.1, but this version cannot run after installing a module that supports XSLT, so it can only use the older but slower version 0.8.
If you don't want other features such as SVG/MathML, the most convenient way is to install them using the prepared .exe file.
After the installation is complete, start Mozilla and visit this page: /projects/xslt/
There is an Install button on the page. Click this button to install the TransforMiiX module that implements XSLT function.
Restart Mozilla and visit the page mentioned above. Click the link above in simple example. If the results you see are the same as those you see when clicking on the look like link, then your Mozilla will already support XSLT.
Regarding how to configure Mozilla 0.8 to support Java Plug-in, please refer to another post I posted in the XML version: a XML client solution based on Mozilla, I won't talk about it here.
Step 7. Install an editor for XML files.
This step is even more necessary. Have you heard that anyone else uses vi to make HTML pages now? I have seen such a person, 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 to facilitate those who are used to using the WYSIWYG editor, I still recommend a few better XML editors:
1. XML Spy: An XML editor with full functions, available for download with a trial version.
/
2. EditML Pro: Another XML editor with relatively complete functionality.
3. PSGML for Emacs: Emacs, I don’t need to say anything, right?
/projects/about_psgml.html
Here we are just to add icing on the cake and introduce some other knowledge. Using this knowledge we can build a more powerful development environment.
Step 8. Install a better JSP Framework
Struts is recommended. Struts is a sub-project of the Jakarta project, with the aim of developing a JSP Framework based on the MVC design pattern. Development within the framework of Struts can effectively separate the presentation layer and implementation layer of web applications and improve the reusability of code. Development based on MVC design model is the so-called Model 2 development model. The project is close to completion, and the latest version is 1.0-beta-1.
For what is an MVC design model, please refer to the book "Design Model" by the Machinery Industry Press. For the usage of Struts, you can refer to the "Struts User Guide" I translated, in the collection of articles: /doc/
Download Jakarta Struts from here:
/builds/jakarta-struts/release/v1.0-b1/
You need to download jakarta-struts-1. This file.
Unzip it, then copy the two files in it 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 and use it if you can register correctly.
Struts' documentation is also installed,
http://localhost:8080/struts-documentation/
For information about how to use Struts in your own development directory, please refer to the documentation provided by Struts. There are some discussions about Struts in the Java version, which can be found using the forum's search function.
Step 9. Establish a connection to Apache
This is an old growth talk. I will introduce the easiest way to use mod_jk to establish a connection with Apache.
Assuming you have Apache installed, download mod_jk from here:
/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 and add the following two lines:
Include C:/tomcat/conf/mod_jk.conf-auto
JkMount /*.do ajp12
Where "C:/tomcat" is the installation directory of Tomcat.
Add to DirectoryIndex, i.e.:
DirectoryIndex
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 you can list the jsp and servlet directories, the connection between Tomcat and Apache is established.
OK, I said so much, but I was just sorting out the housework. Now that the housekeeping is sorted out, we can start XML development. :-)
Establishing 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 an XSLT-enabled browser.
7. Install an editor for XML file (optional).
Step 1. Install Java runtime environment
It is recommended to use Sun's JRE 1.3, which can be downloaded from here:
/j2se/1.3/jre/
Note: Not JDK 1.3, all we need is JRE 1.3
After downloading JRE 1.3, run the installer, assuming it is installed under C:\JRE1.3. Then three environment variables need to be set.
JAVA_HOME=C:\JRE1.3
CLASSPATH=.;C:\JRE1.3\lib\
PATH=%PATH%;C:\JRE1.3\bin
If it is Windows 95/98/me, put the settings of the environment variable in , and then restart the machine, and set Windows NT/2000 in "My Computer/Properties".
Step 2: Install a Java compiler.
It is recommended to use IBM's jikes, a Java compiler with efficient open source. Jikes' homepage is
/developerworks/opensource/jikes/
The latest version is 1.1.3, which can be downloaded from here:
/pub/jikes/jikes-1_13
After downloading, unzip it and get a directory in any PATH environment variable, such as C:\JRE1.3\bin
Try editing a simple hello world program:
//
public class hello {
public static void main(String [] args) {
("hello, world!\n");
}
}
Then compile
jikes
If generated, it can be used.
Step 3. Install a JSP Container.
Jakarta's Tomcat 3.2.1 is recommended. Tomcat 3.2.1 can be downloaded from here:
/builds/jakarta-tomcat/release/v3.2.1/bin/
You need to download jakarta-tomcat-3.2.
If you are installing under Windows NT/2000, there is also jk_nt_service.zip in the win32/i386 directory.
Decompress after downloading, assuming it is placed under C:\tomcat
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 the environment variable CLASSPATH in the lib directory of tomcat, and perform the following steps after it takes effect:
cd \tomcat\src\org\apache\tomcat\context
Edit the file and
// ("jspCompilerPlugin", "");
Remove the previous comment
Then compile
jikes
Create a temporary directory and use the jar tool (available from the JDK) to unzip the Tomcat lib directory
mkdir t
cd t
jar xvf ..\
Replace WebXmlReader*.class under org\apache\tomcat\context with the WebXmlReader*.class that was just compiled and generated
Then repackage:
jar cf .
Replace Tomcat's
Edit Tomcat's conf directory to
<!-- uncomment the following to use Jikes for JSP compilation
<init-param>
<param-name>jspCompilerPlugin</param-name>
<param-value></param-value>
</init-param>
-->
Remove the comments from the outside.
Edit Tomcat's bin directory and replace all
Start tomcat and run bin directory.
Use the browser to do a test and access
http://localhost:8080
If both JSP and Servlet examples can be compiled and run, Tomcat will be used.
Stop Tomcat
Under Windows NT/2000, tomcat can be installed as a service, as follows:
Copy and edit the Tomcat conf directory. Put two of these variables
wrapper.tomcat_home
wrapper.java_home
Set the installation paths to TOMCAT and JRE respectively, and replace all with .
Then run
jk_nt_service -I Tomcat
Where Tomcat is the name of the service we installed.
Go to Control Panel to start Tomcat service. After the Tomcat service is installed, it is set to manually start. You can modify the properties of the Tomcat service to make it automatically start.
Delete Tomcat service with:
jk_nt_service -R Tomcat
Step 4. Install a taglib that supports XSLT.
Recommended XSL Taglib for XSLT in Jakarta Taglibs
Its page is in /taglibs/doc/xsl-doc/
Download snapshot of XSL Taglib from this page. You can also download all Jakarta Taglibs. Jakarta Taglibs has a wide range, but what we want to use here is the XSL Taglibs.
After downloading, unzip, copy the two files and the files into the webapps directory of Tomcat, and then restart Tomcat. Access using a browser
http://localhost:8080/xsl-examples/
If there is no error in the running page, it displays a page with many tables, and XSL Taglib can be used.
The XSL Taglib documentation is also installed,
http://localhost:8080/xsl-doc/
You can start writing your own XML handler step by step based on this example. For example, you can add a new Context to Tomcat
<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 in Tomcat's webapps/xsl-examples directory to your development directory intact, and start writing your own XML handler with this program as a reference.
Regarding how to use JSP for XML development, please refer to Sun's whitepaper, at: /products/jsp/pdf/
What I'm talking about is basically the method I told you above.
Step 5. Install an XML Parser.
After completing Step 3 and Step 4, you already have two available XML Parsers, namely Sun's JAXP and Xerces used by XSL Taglib. JAXP includes two files and , Xerces has only one file , these files can be found in the Tomcat directory.
It is recommended to use Xerecs XML Parser because it can currently support XML Schema and it is open source software. But it's all out of personal preference, Sun's XML Parser is also excellent. Decide which XML Parser to use and add its file to CLASSPATH. But don't use two XML Parsers at the same time. After CLASSPATH takes effect, you can use the JDOM and SAX APIs to process XML files in your Java program.
Examples of the occasions and usages of JDOM and SAX can be found here:
Step 6. Install an XSLT-enabled browser.
This step is not necessary, because we can now convert XML files to HTML format and send them to Browser using XSL Taglib on the Server side, so you can actually 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, after the browsers that support XSLT become popular in the future, we can even save this step and just send the XML and XSL files 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. Speaking of this, you may be asking again, why not use IE 4/5? IE 4/5 can also do XSLT? In addition to personal preferences, I can give you 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:///TR/WD-xsl , and the XSLT supported by Mozilla is the official version of XSLT. That is: http:///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 terms of breadth and depth.
The author of the third XML FAQ highly praised Mozilla, believing that Mozilla's support for XML is much better than IE 4/5 in terms of robustness.
OK, after saying so much, now turn to the topic, how to make Mozilla 0.8 support XSLT?
First, download Mozilla 0.8 from here: /releases/
The latest one is version 0.8.1, but this version cannot run after installing a module that supports XSLT, so it can only use the older but slower version 0.8.
If you don't want other features such as SVG/MathML, the most convenient way is to install them using the prepared .exe file.
After the installation is complete, start Mozilla and visit this page: /projects/xslt/
There is an Install button on the page. Click this button to install the TransforMiiX module that implements XSLT function.
Restart Mozilla and visit the page mentioned above. Click the link above in simple example. If the results you see are the same as those you see when clicking on the look like link, then your Mozilla will already support XSLT.
Regarding how to configure Mozilla 0.8 to support Java Plug-in, please refer to another post I posted in the XML version: a XML client solution based on Mozilla, I won't talk about it here.
Step 7. Install an editor for XML files.
This step is even more necessary. Have you heard that anyone else uses vi to make HTML pages now? I have seen such a person, 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 to facilitate those who are used to using the WYSIWYG editor, I still recommend a few better XML editors:
1. XML Spy: An XML editor with full functions, available for download with a trial version.
/
2. EditML Pro: Another XML editor with relatively complete functionality.
3. PSGML for Emacs: Emacs, I don’t need to say anything, right?
/projects/about_psgml.html
Here we are just to add icing on the cake and introduce some other knowledge. Using this knowledge we can build a more powerful development environment.
Step 8. Install a better JSP Framework
Struts is recommended. Struts is a sub-project of the Jakarta project, with the aim of developing a JSP Framework based on the MVC design pattern. Development within the framework of Struts can effectively separate the presentation layer and implementation layer of web applications and improve the reusability of code. Development based on MVC design model is the so-called Model 2 development model. The project is close to completion, and the latest version is 1.0-beta-1.
For what is an MVC design model, please refer to the book "Design Model" by the Machinery Industry Press. For the usage of Struts, you can refer to the "Struts User Guide" I translated, in the collection of articles: /doc/
Download Jakarta Struts from here:
/builds/jakarta-struts/release/v1.0-b1/
You need to download jakarta-struts-1. This file.
Unzip it, then copy the two files in it 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 and use it if you can register correctly.
Struts' documentation is also installed,
http://localhost:8080/struts-documentation/
For information about how to use Struts in your own development directory, please refer to the documentation provided by Struts. There are some discussions about Struts in the Java version, which can be found using the forum's search function.
Step 9. Establish a connection to Apache
This is an old growth talk. I will introduce the easiest way to use mod_jk to establish a connection with Apache.
Assuming you have Apache installed, download mod_jk from here:
/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 and add the following two lines:
Include C:/tomcat/conf/mod_jk.conf-auto
JkMount /*.do ajp12
Where "C:/tomcat" is the installation directory of Tomcat.
Add to DirectoryIndex, i.e.:
DirectoryIndex
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 you can list the jsp and servlet directories, the connection between Tomcat and Apache is established.
OK, I said so much, but I was just sorting out the housework. Now that the housekeeping is sorted out, we can start XML development. :-)