The ColdFusion Sample Application
|
73
Understanding the XML Parser
The parseXml class uses Xerces and Xalan parsers to format the XML into a
style sheet to return to the browser as HTML. The file
parseXml.java
contains
the following class definition:
parseXml.java class
import com.allaire.cfx.*;
import org.apache.xalan.*;
import org.apache.xerces.*;
import java.io.*;
import java.net.*;
public class parseXml implements CustomTag
{
public void processRequest( Request request, Response response )
throws Exception,java.io.IOException,
java.net.MalformedURLException,
org.xml.sax.SAXException
{
// validate that required attributes were passed
if ( !request.attributeExists( "XML" ) ||
!request.attributeExists( "XSL" ) )
{
throw new Exception(
"<FONT SIZE=4 COLOR=Red>Error</FONT><br>" +
"<B>(XML and XSL must be specified)</B>" ) ;
}
String strXML = request.getAttribute( "XML" ) ;
String strXSL = request.getAttribute( "XSL" ) ;
// Use XSLTProcessorFactory to instantiate an XSLTProcessor.
org.apache.xalan.xslt.XSLTProcessor processor =
org.apache.xalan.xslt.XSLTProcessorFactory.getProcessor();
// Create 3 objects for XSLTProcessor to do the transformation.
org.apache.xalan.xslt.XSLTInputSource xmlSource =
new org.apache.xalan.xslt.XSLTInputSource (strXML);
org.apache.xalan.xslt.XSLTInputSource xslSheet =
new org.apache.xalan.xslt.XSLTInputSource (strXSL);
StringWriter writer = new StringWriter();
org.apache.xalan.xslt.XSLTResultTarget xmlResult =
new org.apache.xalan.xslt.XSLTResultTarget(writer);
// Perform the transformation.
processor.process(xmlSource, xslSheet, xmlResult);
response.write(xmlResult.getCharacterStream().toString());
processor.reset();
processor =
null;
Содержание 15606-011408-9330 - MAPGUIDE R6.3 SITE LIC-UPG R6
Страница 1: ...April 2004 Autodesk MapGuide LiteView Developer s Guide ...
Страница 12: ...8 Chapter 1 Introduction ...
Страница 38: ...34 Chapter 2 Understanding Requests ...
Страница 90: ...86 Chapter 4 Configuring and Using the Sample Applications ...