Error Handling In Xslt Using Jaxp 1.2
from a Java application or servlet. Embedding the processor into a Java application is generally a matter of including one or two JAR files on the CLASSPATH and then invoking the appropriate methods. This chapter shows how to do this, along with a whole host of other programming techniques. When invoked from the command line, an XSLT processor such as Xalan expects the location of an XML file and an XSLT stylesheet to be passed as parameters. The two files are then parsed into memory using an XML parser such as Xerces or Crimson, and the transformation is performed. But when the XSLT processor is invoked programmatically, you are not limited to using static files. Instead, you can send a precompiled stylesheet and a dynamically generated DOM tree directly to the processor, or even fire SAX events as processor input. A major goal is to eliminate the overhead of parsing, which can dramatically improve performance. This chapter is devoted to Java and XSLT programming techniques that work for both standalone applications as well as servlets, with a particular emphasis on Sun's Java API for XML Processing (JAXP) API. In Chapter 6, we will apply these techniques to servlets, taking into account issues such as concurrency, deployment, and performance. A Simple Example Let's start with perhaps the simplest program that can be written. For this task, we will write a simple Java program that transforms a static XML data file into HTML using an XSLT stylesheet. The key benefit of beginning with a simple program is that it isolates problems with your development environment, particularly CLASSPATH issues, before you move on to more complex tasks. Two versions of our Java program will be written, one for Xalan and another for SAXON. A JAXP implementation will follow in the next section, showing how the same code can be utilized for many different processors. CLASSPATH Problems CLASSPATH problems are a common culprit when your code is not working, particularly with XML-related APIs. Since so many tools now use XML, it is very likely that a few different DOM and SAX implementations reside on your system. Before trying any of the examples in this chapter, you may want to verify that older parsers are not listed on your CLASSPATH. More subtle problems can occur if an older library resides in the Java 2 optional packages directory. Any JAR file found in the jre/lib/ext directory is automatically available to the JVM without being added to the CLASSPATH. You should look for files such a
See also the JAXP FAQ for more information. Note: If you are reading this page online, this is the most current version of the release notes. If this page was downloaded as part of the release bundle, please see the JAXP Documentation page for the most current version of the release notes. Contents Identifying the JAR Files Deploying the JAR Files Finding the JAR Files Using the JAR Files XML Parsing Known Schema Processing Limitations in JAXP 1.2 Known Migration Issues from JAXP 1.1 XSLT Processing The Classic Xalan XSLT Processor The Xalan Compiling Processor (XSLTC) Localization Issues Custom Class Loader Issue Manually Specifying http://www.ling.helsinki.fi/kit/2004k/ctl257/JavaXSLT/Ch05.html which XSLT Implementation to Use Automatically Choosing with the Smart Transformer Switch JWSDP Security Considerations Changes in JAXP RI Versions Changes in JAXP RI version 1.2.0-FCS Changes In JAXP RI version 1.2.0-EA2 Changes in JAXP RI version 1.2.0-EA1 Identifying the JAR Files This release is contained in six JAR files: jaxp-api.jar The javax.xml.parsers and javax.xml.transform components of JAXP. These packages contain the APIs that give applications a consistent way http://people.apache.org/~edwingo/jaxp-ri-1.2.0-fcs/docs/ReleaseNotes.html to obtain instances of XML processing implementations. sax.jar The APIs and helper classes for the Simple API for XML (SAX), used for serial access to XML data. dom.jar The APIs and helper classes for the Document Object Model (DOM), used to create an in-memory tree structure from the XML data. xercesImpl.jar The implementation classes for the SAX and DOM parsers, as well as Xerces-specific implementations of the JAXP APIs.. xalan.jar The "classic" Xalan XSLT processor. xsltc.jar The Xalan Compiling XSLT processor. Deploying the JAR Files If you are installing or updating the full Web Services Pack, there are no other configuration steps you need to take. The installation/update process takes care of the details for you. If you are using the Java XML Pack, on the other hand, or if you are using JAXP by itself with the Java 2 platform, then you'll need to follow the instructions below. Finding the JAR Files If you downloaded the Java XML Pack, the JAR files are in:
2.0.1 Null handlers are possible IOException added to SAX EntityResolver API New Features and Properties Invoking XSLT Invoking XSLT from the Command Line Programmatic Access to Xalan XPath Package Name http://docs.oracle.com/cd/E17802_01/webservices/webservices/docs/1.6/jaxp/JAXP-Compatibility_150.html Changes What Changed, and Why Using System Properties and Implementation Classes Security Issue Posed by Nested Entity Definitions Introduction The J2SE 1.4 platform included the "Crimson" reference implementation for JAXP 1.1. The J2SE 1.5 platform includes a reference implementation for JAXP 1.3 based on the Apache "Xerces" library. Because these implementations come from entirely different codebases, and because the JAXP standard has evolved from 1.1 to 1.3, there are some subtle error handling differences between the implementations, even though they both conform to the JAXP standard. These two factors combine to create the compatibility issues described in this guide. Note: The reference implemention for the JAXP 1.3 APIs will be under development for some time. The latest version can always be found at java.net. What's New JAXP 1.3, which is part of the J2SE 1.5 platform, provides some compelling features: A built-in validation processor for error handling in XML Schema. The ability to use other schema validators, as well, with the javax.xml.validation package. A thorough implementation of XML Schema data types in javax.xml.datatype, including Gregorian Calendar dates and times that previously had no natural analogues in the Java platform. XSLTC, the fast, compiling transformer, which is now the default engine for XSLT processing. DOM Level 3 core, which provides: XML 1.1 and Namespaces 1.1 (javax.xml.namespace) which provide better support for unicode characters in tag names and namespaces. Support for normalization of documents Support for schema datatypes (TypeInfo) Better ErrorHandling and identification of an error's location Bootstrapping. DOMLevel 3 supports implementation independent way to obtain DOMImplementation. DOMLevel 3 allows setting of application data in a node, also allows setting of UserDataHandler which gets called whenever a node is cloned, removed, renamed. Java-Centric XPath APIs in javax.xml.xpath, which provide a more java-friendly way to use an XPath expression. It was designed to be applicable to any data model that implments the interface. You can use it now to process the reference implementation DOM. In the future, it is likely to be available when processing a JDom, or STaX data model, as well. An implementation of XInclude, which makes it possible to build a document using text or XML stored in reusable segments els