public static List<Node> findNodes(NodeWithChildren node, NodeFilter<Node> filter) { List<Node> answer = node.getNodes(filter); List<Node> children = node.getNodes(); for (Node child : children) { if (child instanceof Element) { List<Node> childMatched = findNodes((Element) child, filter); answer.addAll(childMatched); } } return answer; }
public static List<Node> findNodes(NodeWithChildren node, NodeFilter<Node> filter) { List<Node> answer = node.getNodes(filter); List<Node> children = node.getNodes(); for (Node child: children) { if (child instanceof Element) { List<Node> childMatched = findNodes((Element) child, filter); answer.addAll(childMatched); } } return answer; }
/** Write all children of a node */ public void writeChildNodes (NodeWithChildren node) throws IOException { for (Node n: node.getNodes ()) n.toXML (this); }
protected Node replaceNamespace(Node node, String oldNS, String newNS) { if (node instanceof Element) { String ns = getNamespaceURI(node); if (ns != null && ns.equals(oldNS)) { Namespace namespace = ((Element) node).getNamespace(); if (namespace != null) { if (namespace.getURI() != null && namespace.getURI().equals(oldNS)) { ((Element) node).setNamespace(new Namespace(namespace.getPrefix(), newNS)); } } for (Attribute attr : ((Element) node).getAttributes()) { if (attr.getName().startsWith("xmlns")) { String value = attr.getValue(); if (value != null && value.equals(oldNS)) { attr.setValue(newNS); } } } } } if (node instanceof NodeWithChildren) { for (Node n : ((NodeWithChildren) node).getNodes()) { replaceNamespace(n, oldNS, newNS); } } return node; }
protected Node replaceNamespace(Node node, String oldNS, String newNS) { if (node instanceof Element) { String ns = getNamespaceURI(node); if (ns != null && ns.equals(oldNS)) { Namespace namespace = ((Element) node).getNamespace(); if (namespace != null) { if (namespace.getURI() != null && namespace.getURI().equals(oldNS)) { ((Element) node).setNamespace(new Namespace(namespace.getPrefix(), newNS)); } } for (Attribute attr : ((Element) node).getAttributes()) { if (attr.getName().startsWith("xmlns")) { String value = attr.getValue(); if (value != null && value.equals(oldNS)) { attr.setValue(newNS); } } } } } if (node instanceof NodeWithChildren) { for (Node n : ((NodeWithChildren) node).getNodes()) { replaceNamespace(n, oldNS, newNS); } } return node; }