4.10 Document Locator

<..SAX locator..>
   Locator locator;
 public void setDocumentLocator(Locator locator){
   this.locator = locator;
 }
 public void startDocument(){ traceLoc( "start" ); }
 public void startElement(String ns, String sname,
         String qName, Attributes atts) { traceLoc( qName ); }
 void traceLoc( String s ){
    System.out.println( locator.getLineNumber() + ": " + s ); }
-_-_-
<?xml version="1.0" encoding="UTF-8"?>  
<document title="red" canvas="yellow">  
  <section>  
    <title>First section</title>  
    <sentence>Some text.</sentence>  
    <sentence>More text.</sentence>  
  </section>  
  <section>  
    <title>Second section</title>  
    <sentence>Another text.</sentence>  
    <sentence>Yet more text.</sentence>  
  </section>  
</document>  
1: start  
2: document  
3: section  
4: title  
5: sentence  
6: sentence  
8: section  
9: title  
10: sentence  
11: sentence