Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Xml Normalize All of the Text in a Document

Related Tutorials


 
 

Share on Google+Share on Google+

Normalize All of the Text in a Document

Advertisement
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"?>
<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

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  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.

Posted on: August 24, 2008

Related Tutorials

Discuss: Normalize All of the Text in a Document  

Post your Comment


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