XmlUtil { public static boolean containsElements(NodeList nodeList) { for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node instanceof Element) { return true; } } return false; }  static Document createDom(); static Document createDOMDocument(String xml); static String prettyFormatXml(String xml, String encoding); static String domToString(Node node, String encoding, boolean pretty); static Node findNode(Node document, String xPathExpression); static Element getFirstElement(Node node); static boolean containsElements(NodeList nodeList); static XMLGregorianCalendar newXMLGregorianCalendar(Date date); static T unmarshal(Class<T> targetClass, String xml); static String marshal(T object); static Source getSource(String xml);  }
@Test public void testContainsElements() throws ProblemException { { final String xml = "<root><elem attr=\"value\">content</elem></root>"; Document dom = XmlUtil.createDOMDocument(xml); assertTrue(XmlUtil.containsElements(dom.getChildNodes())); } { final String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root><elem attr=\"value\">content</elem></root>"; Document dom = XmlUtil.createDOMDocument(xml); assertTrue(XmlUtil.containsElements(dom.getChildNodes())); } { final String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!--komentar--><root> <!--komentar--> <elem attr=\"value\">content</elem></root>"; Document dom = XmlUtil.createDOMDocument(xml); assertTrue(XmlUtil.containsElements(dom.getChildNodes())); assertTrue(XmlUtil.containsElements(dom.getDocumentElement().getChildNodes())); } { final String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!--komentar--><root> <!--komentar--> </root>"; Document dom = XmlUtil.createDOMDocument(xml); assertTrue(XmlUtil.containsElements(dom.getChildNodes())); assertFalse(XmlUtil.containsElements(dom.getDocumentElement().getChildNodes())); } }