@Override public Document addNode (Node node) { super.addNode (node); return this; }
@Override public Element addNodes (Collection<? extends Node> nodes) { super.addNodes (nodes); return this; }
public NodeWithChildren copy () { NodeWithChildren n = (NodeWithChildren)createClone (); n.copy (this); return n; } }
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 Element copy () { return (Element)super.copy (); }
@Override public boolean removeNode (Node n) { if (n != null) { if (n.equals (xmlDeclaration)) clearXMLDeclaration (); else if (n.equals (rootNode)) rootNode = null; } return super.removeNode (n); }
public boolean hasNodes () { return nodeCount () != 0; }
public String getPath () { if (path == null) { NodeWithChildren n = currentNode (); if (n.getType () == Type.DOCUMENT) path = "/"; else path = ((Element)n).getChildPath (); } return path; }
public Node next () { Node n = currentNode ().getNode (getCursor ()); incCursor (); if (XMLUtils.isElement (n)) { Element e = (Element)n; if (e.hasNodes ()) push (e); } return n; }
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 Document copy () { return (Document)super.copy (); }
@Override public Node removeNode (int index) { Node n = getNode (index); if (n.equals (xmlDeclaration)) clearXMLDeclaration (); else if (n.equals (rootNode)) rootNode = null; return super.removeNode (index); }
public boolean hasNext () { while (true) { if (stack.isEmpty ()) return false; if (getCursor () == currentNode ().nodeCount ()) { pop (); continue; } return true; } }
/** Write all children of a node */ public void writeChildNodes (NodeWithChildren node) throws IOException { for (Node n: node.getNodes ()) n.toXML (this); }
@Override public Element addNodes (Node... nodes) { super.addNodes (nodes); return this; }
@Override public Element addNode (Node node) { super.addNode (node); return this; }
public Document copy (Node orig) { super.copy (orig); Document other = (Document)orig; this.xmlDeclaration = other.xmlDeclaration.copy (); this.docType = other.docType; if (other.namespaces != null) this.namespaces = other.namespaces.copy (); return 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; }
@Override public Document addNodes (Node... nodes) { super.addNodes (nodes); return this; }
public NodeWithChildren addNodes (int index, Collection<? extends Node> nodes) { for (Node node: nodes) addNode (index++, node); return this; }