Home Xml Normalize All of the Text in a Document



Normalize All of the Text in a Document
Posted on: August 24, 2008 at 12:00 AM
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

     

Related Tags for Normalize All of the Text in a Document:
cdomormtextmethodsmethodsedgetthisnodeelementooroottexforexampletoexamextedocdesnormalizingliuseinnormmntestdemallnormalizemedodescribexawhichxampsisllmplarxtzscrssrithbelobespleplodsodeomonormnormanor


More Tutorials from this section

Ask Questions?    Discuss: Normalize All of the Text in a Document  

Post your Comment


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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.