/** * Searches the given parent element for a child element matching the given * XPath expression. Please note that the XPath parser used is NOT namespace * aware. So if you want to find an element * <code><beans><sec:http></code>, you need to use the following * XPath expression '/beans/http'. * * @param xPathExpression the xPathExpression (required) * @param parent the parent DOM element (required) * @return the Element if discovered (null if no such {@link Element} found) */ public static Element findFirstElement(final String xPathExpression, final Node parent) { final Node node = findNode(xPathExpression, parent); if (node instanceof Element) { return (Element) node; } return null; }
private static void addCommentBefore(final Element element, final String comment, final Document document) { if (null == XmlUtils.findNode("//comment()[.=' " + comment + " ']", document.getDocumentElement())) { document.getDocumentElement().insertBefore(document.createComment(" " + comment + " "), element); addLineBreakBefore(element, document); } }
Element detailBand = XmlUtils.findFirstElement( "/jasperReport/detail/band", jasperReport); Node backgroundNode = XmlUtils.findNode("/jasperReport/background", jasperReport); for (FieldMetadata fieldMetadata : usableFields) {