BizTalk Utilities CV ,   Jobs ,   Code library  
 
Home Page
XALAN
XALAN Getting Started with XSLTC
The Usage of XALAN
Overview of XALAN - Java
<< WCF, WS, SOAP
XHTML >>

By :Mark Wilson
I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
First posted :03/24/2008
Times viewed :663

 

Xalan: The javax.xml.transform.sax.TemplatesHandler Class

Extends: org.xml.sax.ContentHandler

Members

Signature

Public methods

java.lang.String

getSystemId()

Templates

getTemplates()

void

setSystemId(java.lang.String systemID)

Members inherited from org.xml.sax.ContentHandler

Signature

Public methods

void

characters(char[] ch, int start, int length)

void

endDocument()

void

endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName)

void

endPrefixMapping(java.lang.String prefix)

void

ignorableWhitespace(char[] ch, int start, int length)

void

processingInstruction(java.lang.String target, java.lang.String data)

void

setDocumentLocator(Locator locator)

void

skippedEntity(java.lang.String name)

void

startDocument()

void

startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, Attributes atts)

void

startPrefixMapping(java.lang.String prefix, java.lang.String uri)

Overview

This class is a SAX ContentHandler that may be used to process SAX parse events (parsing transformation instructions) into a Templates object. This is the alternate way of getting compiled stylesheets. In my other transformation related tutorial, I have used the raw stylesheet( passed uri of stylesheet to the transform() method to perform transformation). This class provided alternate way of parsing the stylesheet and converting the stylesheet into Templates object.

This is class provides mechanism of how to get Templates object. So user can control any error that might occur during parsing mechanism. If any error occurs no further processing can be done so utilization of resources can be utilized properly.

Method Overviews

I will covering here, how to get Templates object from a stylesheet. When a TemplatesHandler object is used as a ContentHandler for the parsing of transformation instructions, it creates a Templates object, which the caller can get once the SAX events have been completed.

Example of getTemplates():

getTemplates()  is used to get javax.xml.transform.Templates object.

try{

            TransformerFactory tFactory = TransformerFactory.newInstance();

            // Determine whether the TransformerFactory supports The use of SAXSource

            // and SAXResult

            if (tFactory.getFeature(SAXSource.FEATURE) &&

                tFactory.getFeature(SAXResult.FEATURE)) {

                // Cast the TransformerFactory.

                SAXTransformerFactory saxTFactory = ((SAXTransformerFactory)

                        tFactory);

                // Create a ContentHandler to handle parsing of the stylesheet.

                TemplatesHandler templatesHandler = saxTFactory.

                        newTemplatesHandler();

               // TemplatesHandlerImpl tImpl = (TemplatesHandlerImpl)templatesHandler;

                // Create an XMLReader and set its ContentHandler.

                XMLReader reader = XMLReaderFactory.createXMLReader();

                reader.setContentHandler(templatesHandler);

               

                // Parse the stylesheet.                       

                reader.parse(stylesheetURI);

               

                //Get the Templates object from the ContentHandler.

                Templates templates = templatesHandler.getTemplates();

                // Create a ContentHandler to handle parsing of the XML source.

                TransformerHandler handler

                        = saxTFactory.newTransformerHandler(templates);

                // Reset the XMLReader's ContentHandler.

                reader.setContentHandler(handler);

               

                // Set the ContentHandler to also function as a LexicalHandler, which

                // includes "lexical" events (e.g., comments and CDATA).

                reader.setProperty(

                        "http://xml.org/sax/properties/lexical-handler",

                        handler);

                FileOutputStream fos = new FileOutputStream(outURI);

                //SerializerFactory.getSerializerFactory().;

                java.util.Properties prop = OutputPropertiesFactory.getDefaultMethodProperties("xml");

                Serializer serializer = SerializerFactory.getSerializer(prop);

                serializer.setOutputFormat(prop);

                // Set the result handling to be a serialization to the file output stream.

                Result result = new SAXResult(serializer.asContentHandler());

                handler.setResult(result);

                // Parse the XML input document.

                InputSource src = new InputSource(xmlfileURI);

                reader.parse(src);

               

            }

        }catch(Exception e){

            e.printStackTrace();

        }.

Example of getSystemId():

getSystemId()  is used to get the base ID (URI or system ID) from where relative URLs will be resolved.

templatesHandler.getSystemId();


Rate this article on a scale of 1 to 10

Your vote :  


 

Recent Jobs

A great opportunity to Digital Vide
here is a greate opportunity as a S
A great opportunity as a Network En
A Greate Opportunituy as a SQL Deve
An immediate job opportunity as a B

View all Jobs (Add yours)
View all CV (Add yours)



Information Online

swimming pool builder
chicago web site design
affordable conference calls
Domain Names
conference call services
Emporio armani sunglasses
answering service


    Email TopXML  

Front Page Daily Stuff TopXML Forum XML blogs XML Newsgroups BizTalk Biztalk Utilities Biztalk Utilities Tutorial B2B SAP XML Microsoft .NET Dotnet System XML Soapformatter SQLXML XMLserializer XQuery PHP PHP SimpleXML PHP XML Dom PHP XML RPC PHP XSLT Java Java Java XML Xalan Microsoft ASP ASP Schemas XML SQL Server XML XMLDom XSL XSL Tutorial XSLT Stylesheets General Javascript CSS XHTML WAP