+ // FIXME: unchecked cast
+ return ((DataContainerNode) nStateNode.get()).findChildByArg(toId(Schemas.QNAME));
+ }
+
+ @VisibleForTesting
+ static DOMSource ietfMonitoringCopy(final DOMSource domSource) {
+ final var sourceDoc = XmlUtil.newDocument();
+ sourceDoc.appendChild(sourceDoc.importNode(domSource.getNode(), true));
+
+ final var treeWalker = ((DocumentTraversal) sourceDoc).createTreeWalker(sourceDoc.getDocumentElement(),
+ NodeFilter.SHOW_ALL, node -> {
+ final var namespace = node.getNamespaceURI();
+ return namespace == null || MONITORING_NAMESPACE.equals(namespace)
+ ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT;
+ }, false);
+
+ final var filteredDoc = XmlUtil.newDocument();
+ filteredDoc.appendChild(filteredDoc.importNode(treeWalker.getRoot(), false));
+ final var filteredElement = filteredDoc.getDocumentElement();
+ copyChildren(treeWalker, filteredDoc, filteredElement);
+
+ return new DOMSource(filteredElement);
+ }
+
+ private static void copyChildren(final TreeWalker walker, final Document targetDoc, final Node targetNode) {
+ if (walker.firstChild() != null) {
+ for (var node = walker.getCurrentNode(); node != null; node = walker.nextSibling()) {
+ final var importedNode = targetDoc.importNode(node, false);
+ targetNode.appendChild(importedNode);
+ copyChildren(walker, targetDoc, importedNode);
+ walker.setCurrentNode(node);
+ }
+ }