Ranges appered first in DOM Level 2. This mechanism allows to work with a set of document data fragments. When the range is defined it may be used for copying, modifying and even deleting.

The entry-point there is interface DocumentRange. There is no explicit way like getter method in DOM to get instance of DocumentRange. But most implementations implies that DOM-document realization also implementats this interface. Thus, the following example shows how to get traversal tool from DOM-document:

   // first you get a document somewhere: create or load from a file:
  Document document = loader....;
  // ...
  // then you can simply cast you document instance to range-interface:    
  DocumentRange ranges= (DocumentRange) document;

Parent Category: Java SE Tips