BizTalk Utilities CV ,   Jobs ,   Code library  
 
javax.xml.transform.Templates Class
javax.xml.transform.stream.StreamSource Class
javax.xml.transform.stream.StreamResult Class
javax.xml.transform.Source Class
javax.xml.transform.sax.SAXSource Class
javax.xml.transform.sax.SAXResult Class
javax.xml.transform.Result Class
javax.xml.transform.ErrorListener Class
javax.xml.transform.dom.DOMSource Class
javax.xml.transform.dom.DOMResult Class
javax.xml.parsers.SAXParserFactory Class
javax.xml.parsers.SAXParser Class
javax.xml.parsers.DocumentBuilderFactory Class
javax.xml.parsers.DocumentBuilder Class
SAX 2.0 Features and Properties
MSMQ Mode Tool
XML for Software Configuration
XML - Basics.
RTF to XML converter 1.2
Retriving XML from a Oracle Table using the XDK for PL/SQL
<< XSLT
.NET and XML >>

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 :497

 

The javax.xml.transform.Transformer Class

Super Class : java.lang.Object.

Members

Signature

Public methods

abstract  void

clearParameters()

abstract  ErrorListener

getErrorListener()

abstract  Properties

getOutputProperties()

abstract  String

getOutputProperty(String name)

abstract  Object

getParameter(String name)

abstract  URIResolver

getURIResolver()

abstract  void

setErrorListener(ErrorListener listener)

abstract  void

setOutputProperties(Properties oformat)

abstract  void

setOutputProperty(String name, String value)

abstract  void

setAttribute(String name, Object value)

abstract  void

abstract  void

setURIResolver(URIResolver resolver)

abstract  void

transform(Source xmlSource, Result outputTarget)

Overview

This core abstract class provides XML transformation facility through TrAX and JAXP. This instance may then be used to process XML from a variety of sources and write the transformation output to a variety of sinks.

An object of this class may not be used in multiple threads running concurrently. Different Transformers may be used concurrently by different threads.

A Transformer may be used multiple times. Parameters and output properties are preserved across transformations.

Method Overviews

Important methods of this class are transform() and  setParameter()

Example of transform (source,result)

transform (source,result) method is used to process the source tree to the output result.

/**

   * Method to create a result file from source file. It copies content of source file into

   * result file. This method used java.io.File for transformation.

   */

  public void simpleTransform()

  {

      initializeTransformerFactory();

    try{

    File sourceFile = new File(sourcefileURI);

    File resultFile = new File(resultfileURI);

    StreamResult result = new StreamResult(resultFile);

    StreamSource source = new StreamSource(sourceFile);

    transformer = tFactory.newTransformer();

    transformer.transform(source,result);

    }catch(TransformerException te)

    {

      te.printStackTrace();

    }

  }

Example of setParameter(String name, Object value)

setParameter(String name, Object value) is used to add a parameter for the transformation.

Pass a qualified name as a two-part string, the namespace URI enclosed in curly braces ({}), followed by the local name. If the name has a null URL, the String only contain the local name. An application can safely check for a non-null URI by testing to see if the first character of the name is a '{' character.

For example, if a URI and local name were obtained from an element defined with <xyz:foo xmlns:xyz="http://xyz.foo.com/yada/baz.html"/>, then the qualified name would be "{http://xyz.foo.com/yada/baz.html}foo". Note that no prefix is used.

/**

   * This method uses stylesheel to create a Transformer. Applies the stylesheet to the input

   * xml source and creates result html.

   */

  public void transformUsingStylesheet()

  {

    try{

    File sourceFile = new File(sourceFileURI);

    File resultFile = new File(resultFileURI);

    StreamResult result = new StreamResult(resultFile);

    StreamSource source = new StreamSource(sourceFile);

    Templates template = tFactory.newTemplates(new StreamSource(stylesheetURI));

    transformer = template.newTransformer();

    transformer.setParameter("heading","This is A Parameter Heading");

    transformer.transform(source,result);

    }catch(TransformerConfigurationException tce)

    {

      tce.printStackTrace();

    }catch(TransformerException te)

    {

      te.printStackTrace();

    }

  }


Rate this article on a scale of 1 to 10

Your vote :  


 

Recent Jobs

Software Developers Needed in Charl
Sr. Software Engineer - Analytics
Immediate Mainframe openings for Ch
Immediate TANDEM-TAL openings for C
Immediate ASP.NET/C# Openings for C

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



fax server
swimming pool contractor
teleconferencing
water softener
Teleconference
Host Department NOLIMIT Web Hosting
MSN
sunglasses


    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