AbstractDomXmlRule extends AbstractXmlRule { @Override protected void visit(XmlNode node, RuleContext ctx) { final Node domNode = node.getNode(); visitDomNode(node, domNode, ctx); visitAttributeNodes(node, domNode, ctx); }    }
@Test public void testVisit() throws Exception { String source = "<?xml version=\"1.0\"?><?mypi?><!DOCTYPE testDoc [<!ENTITY entity \"e\">]><!--Comment--><foo abc=\"abc\"><bar>TEXT</bar><![CDATA[cdata!]]>&gt;&entity;&lt;</foo>"; XmlParserOptions parserOptions = new XmlParserOptions(); parserOptions.setExpandEntityReferences(false); Parser parser = LanguageRegistry.getLanguage(XmlLanguageModule.NAME).getDefaultVersion() .getLanguageVersionHandler().getParser(parserOptions); XmlNode xmlNode = (XmlNode) parser.parse(null, new StringReader(source)); List<XmlNode> nodes = new ArrayList<>(); nodes.add(xmlNode); MyRule rule = new MyRule(); rule.apply(nodes, null); List<org.w3c.dom.Node> visited = rule.visitedNodes.get("Attr"); assertEquals(1, visited.size()); assertEquals("abc", visited.get(0).getLocalName()); visited = rule.visitedNodes.get("CharacterData"); assertEquals(1, visited.size()); assertEquals("cdata!", ((CharacterData) visited.get(0)).getData()); visited = rule.visitedNodes.get("Comment"); assertEquals("Comment", ((Comment) visited.get(0)).getData()); visited = rule.visitedNodes.get("Document"); assertEquals(1, visited.size()); visited = rule.visitedNodes.get("DocumentType"); assertEquals("testDoc", ((DocumentType) visited.get(0)).getName()); visited = rule.visitedNodes.get("Element"); assertEquals(2, visited.size()); assertEquals("foo", visited.get(0).getLocalName()); assertEquals("bar", visited.get(1).getLocalName()); visited = rule.visitedNodes.get("EntityReference"); assertEquals(1, visited.size()); assertEquals("entity", ((EntityReference) visited.get(0)).getNodeName()); visited = rule.visitedNodes.get("ProcessingInstruction"); assertEquals(1, visited.size()); assertEquals("mypi", ((ProcessingInstruction) visited.get(0)).getTarget()); visited = rule.visitedNodes.get("Text"); assertEquals(3, visited.size()); assertEquals("TEXT", ((Text) visited.get(0)).getData()); assertEquals(">", ((Text) visited.get(1)).getData()); String text = ((Text) visited.get(2)).getData(); if ("<".equals(text)) { assertEquals("<", ((Text) visited.get(2)).getData()); } else { assertEquals("e<", ((Text) visited.get(2)).getData()); } }