Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
XML
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Transforming XML with SAXFilters

                         

This Example shows you how to Transform XML with SAXFilters. JAXP (Java API for XML Processing) is an interface which provides parsing of xml documents. Here the Document BuilderFactory is used to create new DOM parsers. There are some of the methods used in code given below for Transforming XML with SAXFilters:-

FileReader fileReader = new FileReader("Document2.xml"):-FileReader is a convenience class for reading character files. it is generally meant for reading streams of characters.

CustomFilter filter = new CustomFilter():-creates a custom filter.

XML code for the program generated is:-

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Company>
    <Employee>
        <name Girish="Gi">Roseindia.net
        </name>
    </Employee>
    <Employee>
        <name Komal="Ko">newsTrack
        </name>
    </Employee>
    <Employee>
        <name Mahendra="Rose">Girish Tewari
        </name>
    </Employee>
</Company>
  


XMLwithSAX.java

/* 
 * @Program for Transforming XML with SAXFilters
 * XMLwithSAX.java 
 * Author:-RoseIndia Team
 * Date:-23-July-2008
 */

import org.xml.sax.*;
import org.xml.sax.helpers.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
import javax.xml.transform.sax.*;
import java.io.*;

public class XMLwithSAX {
    public final static void main(String[] args) throws Exception {
        class CustomFilter extends XMLFilterImpl {
        }
        FileReader fileReader = new FileReader("Document2.xml");
        BufferedReader br = new BufferedReader(fileReader);
        InputSource inputSource = new InputSource(br);

        XMLReader parser = XMLReaderFactory.createXMLReader();
        CustomFilter filter = new CustomFilter();
        filter.setParent(parser);

        SAXSource source = new SAXSource(filter, inputSource);
        FileWriter fw = new FileWriter("out.xml");
        BufferedWriter bw = new BufferedWriter(fw);
        StreamResult result = new StreamResult(bw);

        TransformerFactory factory = TransformerFactory.newInstance();
        Transformer transformer = factory.newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.transform(source, result);
    }
}
  


Output of the program:-

<?xml version="1.0" encoding="UTF-8"?>

<Company>

    <Employee>

        <name Girish="Gi">Roseindia.net

        </name>

    </Employee>

    <Employee>

        <name Komal="Ko">newsTrack

        </name>

    </Employee>

    <Employee>

        <name Mahendra="Rose">Girish Tewari

        </name>

    </Employee>

</Company>


Download Source Code

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Latest Searches:
Writing Hello World
ร?ย�ร??ร?ย
prime numbers
Grid using flex
ajax prototype framewo
Murach��??��??
jsf with tomcat
breakะ�?ะ�ะ?
split
add methods jquery
sound formate to wav f
google calender
httpunit tutorial
scalar matrix
code for simple calcul
Struts2 Hibernate
Hibernate code
SimpleHelloByEnteringN
random integer generat
Ajax with JSP
Photoshop Web Graphics
wml
dot prodoct matrix
Facelets tag
parse a int to string
servlets
code for searching rec
update User jsf
??????????????????????
struts option tag
internalframe
JSF selectOneMenu Tag
Solaris 10 OS Released
compare 3 numbers in J
square root loop
axis web services
autosuggest
scalar
wait and notify in a j
ะ�??ะ ย�ะ
struts hibernate
finding max min array
java servlet to write
calendra in jsp
username and password
Constructor Inheritanc
java combo box
constructor
Create Radio Buttons i
how to a changepasswor
ั?ะ�?ั?ะ�?
excel from java
java Color
jboss 4.2.1.GA
JSF Log out
java Concurrency utili
Read the Key-Value of
Combattons la programm
break���?��?
input in array
Display image on JSP p
ะà¸?ะ?ะà¸??ะà¸
what is basic stack in
checkbox for delete
Login Application
export database data i
how to get parameters
example of hibernate
scalar product matrix
readln()
user temp folder
read a file on the ser
jfreechart
ajax php
matrix modulus
jboss seam tutorials
EL Implicit Objects
how to read txt file f
how to print arraylist
JSP scriptlets
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.