1 9 10 package org.dom4j.samples; 11 12 import org.dom4j.Attribute; 13 import org.dom4j.CDATA; 14 import org.dom4j.Comment; 15 import org.dom4j.Document; 16 import org.dom4j.DocumentType; 17 import org.dom4j.Element; 18 import org.dom4j.Entity; 19 import org.dom4j.Namespace; 20 import org.dom4j.ProcessingInstruction; 21 import org.dom4j.Text; 22 import org.dom4j.Visitor; 23 import org.dom4j.VisitorSupport; 24 25 31 public class VisitorDemo extends SAXDemo { 32 33 public static void main(String [] args) { 34 run(new VisitorDemo(), args); 35 } 36 37 public VisitorDemo() { 38 } 39 40 protected void process(Document document) throws Exception { 41 Visitor visitor = new VisitorSupport() { 42 43 public void visit(Document document) { 44 println(document.toString()); 45 } 46 47 public void visit(DocumentType documentType) { 48 println(documentType.toString()); 49 } 50 51 public void visit(Element node) { 52 println(node.toString()); 53 } 54 55 public void visit(Attribute node) { 56 println(node.toString()); 57 } 58 59 public void visit(CDATA node) { 60 println(node.toString()); 61 } 62 63 public void visit(Comment node) { 64 println(node.toString()); 65 } 66 67 public void visit(Entity node) { 68 println(node.toString()); 69 } 70 71 public void visit(Namespace node) { 72 println(node.toString()); 73 } 74 75 public void visit(ProcessingInstruction node) { 76 println(node.toString()); 77 } 78 79 public void visit(Text node) { 80 println(node.toString()); 81 } 82 }; 83 84 document.accept(visitor); 85 } 86 } 87 88 126 | Popular Tags |