Share on Google+Share on Google+

Normalize All of the Text in a Document

In this section, you will learn how to use Normalize all of the text in a DOM document.

Normalize All of the Text in a Document


This Example describes a method to Normalize all of the Text in a DOM document. Methods which are used for Normalizing the text node in the DOM Document are described below :-

Element root = doc.getDocumentElement():-allows direct access to the root of the DOM document.

root.getNodeName():-gives the node name of the root.

root.normalize():-it normalize All of the Text in a Document

Xml code for the program generated is:-

<?xml version="1.0" encoding="UTF-8"?>
  <Companyname>Roseindia .Net</Companyname>
  <Employee>Girish Tewari</Employee>

 * @Program that Normalize All of the Text in a Document
 * Author:-RoseIndia Team
 * Date:-10-Jun-2008

import javax.xml.parsers.*;
import org.w3c.dom.*;

public class NormaliseText {

  public static void main(String[] args) throws Exception {
  DocumentBuilderFactory builderFactory = 


  Document doc = builderFactory.newDocumentBuilder().parse
new File("Document4.xml"));
  new NormaliseText().normalise(doc);

  public void normalise(Document doc) {
  Element root = doc.getDocumentElement();
  System.out.print("root is: " + root.getNodeName());
  //Normalize All of the Text in a Document


Output of the program:-

Normalize root is:  Company

Download Source Code



Posted on: August 24, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: Normalize All of the Text in a Document  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image