June 19, 2011, 6:01 a.m.
posted by franni
Example XML/XSL Web Interface with WSAD
In this section, we will build the example shown in Figure using the static XML document, timesheet.xml. In the next section, we will add a servlet and an XML Generator in order to show you how to use Java to do the transformation. WSAD provides many tools to help create, test, and debug XML and XSL. We will use the tools provided in WSAD to enhance our development efforts. Most of our time will be spent in the Web perspective and the XML perspective. You will follow these steps in implementing the XML/XSL Example using WSAD:
1 Creating a Web Project
In Chapter 7, we learned how to create a Web project. We will primarily use the XML perspective instead of the Web perspective to view this project in this section. Open the XML perspective by selecting Window > Open Perspective > Other… from the menu bar. Select XML from the list of available perspectives (Figure).
Next, create a new Web project by selecting File > New > Web Project. This will bring up the Create a Web Project wizard. Enter the Project Name of XMLXSLExample and specify that this is a J2EE project. Uncheck any checked items for creation. Specify the DefaultEAR project as your enterprise project and enter a Context Root of XMLXSLExample (no spaces). Finally, select J2EE 1.3. Refer to Chapter 7 for details on each of these settings.
Let's look at what was created.
Figure shows the DefaultEAR and XMLXSL Example projects that were created by the Create a Web Project wizard in the Navigator view. To avoid typing, you can import the rest of the files for the example XML/XSL Web interface from the CD. If you do the import, you can skip "Creating the XML file" and "Creating the XSL file" sections and go directly to the "XSL Debugging and Transformation" section. See Apppendix A for instructions on importing examples.
2 Creating the XML file
XML and XSL files do not have to be on the HTTP path in order to be used in a Web application. The HTTP path is a path that is accessible to the Web browser through a URL. We will discuss this in detail later but for now create the XML file in a folder that is not on the HTTP path. Create a folder named XMLSource as a subfolder of the main project folder, XMLXSL Example by first selecting the XMLXSL Example project and then selecting the File > New > Folder menu option. In the wizard, enter the folder name of XMLSource.
Previously, we worked with the timesheet.xml file. Now we need to bring this file into WSAD so that we can use the WSAD tools to test it with our XSL files. Select the XMLSource folder and then select the File > New > Other… menu to display all of the types of files that can be created, as shown in Figure.
Select XML from the list on the left and XML again from the list on the right. Press the Next button to move on to the next screen in the wizard (Figure).
This wizard screen gives several ways to create an XML file. If you had a DTD or XML Schema file, you could generate a sample XML file from either of those. Also, we will see later that you can generate a DTD or XML Schema from an XML file. Select the Create XML file from Scratch radio button. Press the Next button to move on to the next screen in the wizard as shown in Figure.
Enter the name of the XML file as timesheet.xml and press the Finish button to complete the creation of the XML file. The navigator view of WSAD will now resemble Figure.
Additionally, the XML file will be opened in the editor area with the minimal lines for an XML file. You will need to enter the code from the timesheet.xml file as shown earlier in this chapter or import the one from the CD-ROM. Once you have entered the code, save the file and close it.