1 19 20 29 30 package org.netbeans.modules.xml.xdm.visitor; 31 32 import org.netbeans.modules.xml.xdm.nodes.Attribute; 33 import org.netbeans.modules.xml.xdm.nodes.Document; 34 import org.netbeans.modules.xml.xdm.nodes.Element; 35 import org.netbeans.modules.xml.xdm.nodes.Node; 36 import org.netbeans.modules.xml.xdm.nodes.Text; 37 import org.w3c.dom.NodeList ; 38 39 43 public class FindVisitor extends ChildVisitor { 44 45 public Node find(Document root, int targetId) { 46 this.targetId = targetId; 47 result = null; 48 root.accept(this); 49 return result; 50 } 51 52 public Node find(Document root, Node target) { 53 return find(root,target.getId()); 54 } 55 56 protected void visitNode(Node node) { 57 if (node.getId() == targetId) { 58 result = node; 59 return; 60 } else { 61 super.visitNode(node); 62 } 63 } 64 65 private Node result; 66 private int targetId; 67 } 68 | Popular Tags |