public static boolean hasDirectChild(Element parent, String namespace, String tag) {
      NodeList children = parent.getElementsByTagNameNS(namespace, tag);
      for (int i = 0; i < children.getLength(); i++) {
         Node child = children.item(i);
         if (child.getNodeType() == Node.ELEMENT_NODE && child.getParentNode() == parent) {
            return true;
         }
      }
      return false;
   }
@Test
   void hasDirectChild() {
      assertTrue(XmlUtil.hasDirectChild(parent, "http://example.com", "child"));
      assertFalse(XmlUtil.hasDirectChild(parent, "http://example.com", "nonExistentChild"));
   }