/** * Return a Filter that matches any {@link Element} data with the specified * name. * * @param name The name of Elements to match. * @return a Filter that matches any {@link Element} data with the specified * name. */ public static final Filter<Element> element(String name) { return new ElementFilter(name, Namespace.NO_NAMESPACE); }
public Document patch( Document mainDoc, Document appendDoc ) { Document resultDoc = mainDoc.clone(); Element resultRoot = resultDoc.getRootElement(); Element appendRoot = appendDoc.getRootElement(); ElementFilter modFilter = new ElementFilter( modNS ); for ( Content content : appendRoot.getContent() ) { if ( modFilter.matches( content ) ) { Element node = (Element)content; boolean handled = false; List<Element> matchedNodes = handleModFind( resultRoot, node ); if ( matchedNodes != null ) { handled = true; for ( Element matchedNode : matchedNodes ) { handleModCommands( matchedNode, node ); } } if ( !handled ) { throw new IllegalArgumentException( String.format( "Unrecognized mod tag <%s> (%s).", node.getName(), getPathToRoot(node) ) ); } } else { resultRoot.addContent( content.clone() ); } } return resultDoc; }
/** * Return a Filter that matches any {@link Element} data with the specified * name and Namespace. * * @param name The name of Elements to match. * @param ns The Namespace to match * @return a Filter that matches any {@link Element} data with the specified * name and Namespace. */ public static final Filter<Element> element(String name, Namespace ns) { return new ElementFilter(name, ns); }
/** * Return a Filter that matches any {@link Element} data with the specified * Namespace. * * @param ns The Namespace to match * @return a Filter that matches any {@link Element} data with the specified * Namespace. */ public static final Filter<Element> element(Namespace ns) { return new ElementFilter(null, ns); }
/** * This returns the first child element within this element with the * given local name and belonging to the given namespace. * If no elements exist for the specified name and namespace, null is * returned. * * @param cname local name of child element to match * @param ns <code>Namespace</code> to search within. A null implies Namespace.NO_NAMESPACE. * @return the first matching child element, or null if not found */ public Element getChild(final String cname, final Namespace ns) { final List<Element> elements = content.getView(new ElementFilter(cname, ns)); final Iterator<Element> iter = elements.iterator(); if (iter.hasNext()) { return iter.next(); } return null; }
/** * This returns a <code>List</code> of all the child elements * nested directly (one level deep) within this element with the given * local name and belonging to the given Namespace, returned as * <code>Element</code> objects. If this target element has no nested * elements with the given name in the given Namespace, an empty List * is returned. The returned list is "live" in document order * and changes to it affect the element's actual contents. * <p> * Please see the notes for <code>{@link #getChildren}</code> * for a code example. * </p> * * @param cname local name for the children to match * @param ns <code>Namespace</code> to search within. A null implies Namespace.NO_NAMESPACE. * @return all matching child elements */ public List<Element> getChildren(final String cname, final Namespace ns) { return content.getView(new ElementFilter(cname, ns)); }
/** * <p> * This removes all child elements (one level deep) with the * given local name and belonging to the given namespace. * Returns true if any were removed. * </p> * * @param cname the name of child elements to remove * @param ns <code>Namespace</code> to search within. A null implies Namespace.NO_NAMESPACE. * @return whether deletion occurred */ public boolean removeChildren(final String cname, final Namespace ns) { boolean deletedSome = false; final ElementFilter filter = new ElementFilter(cname, ns); final List<Element> old = content.getView(filter); final Iterator<Element> iter = old.iterator(); while (iter.hasNext()) { iter.next(); iter.remove(); deletedSome = true; } return deletedSome; }
/** * <p> * This removes the first child element (one level deep) with the * given local name and belonging to the given namespace. * Returns true if a child was removed. * </p> * * @param cname the name of child element to remove * @param ns <code>Namespace</code> to search within. A null implies Namespace.NO_NAMESPACE. * @return whether deletion occurred */ public boolean removeChild(final String cname, final Namespace ns) { final ElementFilter filter = new ElementFilter(cname, ns); final List<Element> old = content.getView(filter); final Iterator<Element> iter = old.iterator(); if (iter.hasNext()) { iter.next(); iter.remove(); return true; } return false; }
return content.getView(new ElementFilter());
private Optional<Element> findDescendant(Element container, String id) { IteratorIterable<Element> descendants = container.getDescendants(new ElementFilter()); return StreamSupport.stream(descendants.spliterator(), false) .filter(e -> hasOrIncludesID(e, id)).findFirst(); }
/** If mods:genre was not mapped by conversion/import function, ignore this publication and do not import */ private static boolean shouldIgnore(Element publication) { return !publication.getDescendants(new ElementFilter("genre", MCRConstants.MODS_NAMESPACE)).hasNext(); }
/** * Moves all namespace declarations in the children of target to the target. * * @param target the namespace are bundled here */ private void moveNamespacesUp(Element target) { Map<String, Namespace> existingNamespaces = getNamespaceMap(target); Map<String, Namespace> newNamespaces = new HashMap<>(); target.getDescendants(new ElementFilter()).forEach(child -> { Map<String, Namespace> childNamespaces = getNamespaceMap(child); childNamespaces.forEach((prefix, ns) -> { if (existingNamespaces.containsKey(prefix) || newNamespaces.containsKey(prefix)) { return; } newNamespaces.put(prefix, ns); }); }); newNamespaces.forEach((prefix, ns) -> target.addNamespaceDeclaration(ns)); }
protected static Element queryElement(Document n, String query) { return XPathFactory.instance().compile(query, new ElementFilter()).evaluateFirst(n); }
protected static List<Element> queryElements(Document n, String query) { return XPathFactory.instance().compile(query, new ElementFilter()).evaluate(n); }
protected static Element queryElement(Document n, String query) { return XPathFactory.instance().compile(query, new ElementFilter()).evaluateFirst(n); }
protected static List<Element> queryElements(Document n, String query) { return XPathFactory.instance().compile(query, new ElementFilter()).evaluate(n); }
return false; final Iterator<Element> e1Descendants = e1.getDescendants(new ElementFilter()); final Iterator<Element> e2Descendants = e2.getDescendants(new ElementFilter());
String lang = section.getAttributeValue(MyCoReWebPageProvider.XML_LANG, Namespace.XML_NAMESPACE); String data = null; if (section.getContent(new ElementFilter()).size() > 1) { Element div = new Element("div"); while (section.getChildren().size() > 0) {
for (Element pack: test.getDescendants(new ElementFilter("package"))) { if (pack.getAttributeValue("name").contains("com.seleniumtests.core.runner")) { cucumberTest = true;
String field = null; Element elProp = ReportUtils.find(el, "prop", NS_DAV); Iterator propIter = elProp.getContent(new ElementFilter()).iterator(); if(propIter.hasNext()) { Element elPropChild = (Element) propIter.next();