NodeSetFilter extends FullXmlFilter { @Override public void comment(char[] ch, int start, int length) throws SAXException { if (copying) { super.comment(ch, start, length); } } NodeSetFilter(String targetElement, ContentHandler handler);  NodeSetFilter(Map<String,String> namespaceMap, String targetElement, boolean includeTarget, boolean includeRoot, ContentHandler handler); void startNode(String uri, String localName, String qName); void endNode(String uri, String localName, String qName); @Override void startPrefixMapping(String prefix, String uri); @Override void endPrefixMapping(String prefix); @Override void startElement(String uri, String localName, String qName, Attributes atts); @Override void endElement(String uri, String localName, String qName); @Override void characters(char[] ch, int start, int length); @Override void comment(char[] ch, int start, int length); @Override void startCDATA(); @Override void endCDATA(); @Override void startEntity(String name); @Override void endEntity(String name); @Override void ignorableWhitespace(char[] ch, int start, int length);  }
@Test public void testTargetElementMultiNamespace() throws Exception { String namespaceDefs="urn:defns2"; String targetElement="XDOC"; NodeSetFilter nodeSetFilter = new NodeSetFilter(XmlUtils.getNamespaceMap(namespaceDefs), targetElement, true, false, null) { @Override public void startNode(String uri, String localName, String qName) throws SAXException { String msg = "before node ["+qName+"]"; comment(msg.toCharArray(), 0, msg.length()); } @Override public void endNode(String uri, String localName, String qName) throws SAXException { String msg = "after node ["+qName+"]"; comment(msg.toCharArray(), 0, msg.length()); } }; String document=TestFileUtils.getTestFile("/NodeSetFilter/NoDuplicateNamespaces/xdocs.xml"); String expected=TestFileUtils.getTestFile("/NodeSetFilter/NoDuplicateNamespaces/out.txt"); testNodeSetFilter(nodeSetFilter, targetElement, false, document, expected); }
@Test public void testContainerMultiNamespace() throws Exception { String namespaceDefs="urn:defcont"; String containerElement="DocOutputPrintDocumentRequestCont"; NodeSetFilter nodeSetFilter = new NodeSetFilter(XmlUtils.getNamespaceMap(namespaceDefs), containerElement, false, false, null) { @Override public void startNode(String uri, String localName, String qName) throws SAXException { String msg = "before node ["+qName+"]"; comment(msg.toCharArray(), 0, msg.length()); } @Override public void endNode(String uri, String localName, String qName) throws SAXException { String msg = "after node ["+qName+"]"; comment(msg.toCharArray(), 0, msg.length()); } }; String document=TestFileUtils.getTestFile("/NodeSetFilter/NoDuplicateNamespaces/xdocs.xml"); String expected=TestFileUtils.getTestFile("/NodeSetFilter/NoDuplicateNamespaces/out.txt"); testNodeSetFilter(nodeSetFilter, containerElement, false, document, expected); }