9.5 The XML Context View

<..visit xml context node..>
 switch( node.getNodeType() ){
   case   Node.DOCUMENT_NODE: visit((Document) node); break;
   case    Node.ELEMENT_NODE: visit((Element) node);  break;
   case  Node.ATTRIBUTE_NODE: visit((Attr) node);     break;
   default:;
 }
-_-_-

<..the visit methods..>
 void visit(Document node){
   System.out.println( "The root" ); }
 void visit(Element node){
   System.out.println( "Element:  " + node.getTagName() ); }
 void visit(Attr node){
   System.out.println( "Attr:  " + node.getName() ); }
-_-_-
<?xml version="1.0" encoding="UTF-8"?>  
<article xmlns="x:y" attr="ignored">  
  <section>  
    A &amp; B  
  </section>  
</article>  
The root  
Element:  article  
Attr:  xmlns  
Attr:  attr  
Element:  section