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.

Tutorials   

Ads

Ads

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"?>
<Company>
  <Location>
  <Companyname>Roseindia .Net</Companyname>
  <Employee>Girish Tewari</Employee>
  </Location>
</Company>


NormaliseText.java:

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

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

public class NormaliseText {

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

  builderFactory.setValidating(false);

  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
  root.normalize();

  }
}


Output of the program:-

Normalize root is:  Company


Download Source Code

     

Advertisements

Ads
Share on Google+Share on Google+

Normalize All of the Text in a Document

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

Advertisements

 

Discuss: Normalize All of the Text in a Document  

Post your Comment


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

Ads

 

Ads