public String getChildPath () { if (getParent () == null) return getName (); Element p = getParentElement (); if (p == null) return "/" + getName (); int index = p.childIndexOf (this); if (index == 0) return p.getChildPath () + "/" + getName (); return p.getChildPath () + "/" + getName () + "[" + index + "]"; }
public Document getDocument () { Parent p = getParent (); while (p != null) { if (p.getType () == Type.DOCUMENT) return (Document)p; p = ((Child)p).getParent (); } return null; }
private void replace(Element what, Element with) { Parent parent = what.getParent(); int idx = parent.nodeIndexOf(what); what.remove(); parent.addNode(idx, with); }
public static String nodeWithNamespacesToText(Node parseNode, Element namespacesNode) throws IOException { // we need to add any namespace prefixes defined in the root directory Node copy = parseNode.copy(); if (copy instanceof Element && parseNode instanceof Element) { moveCommentsIntoDescriptionElements((Element) copy, (Element) parseNode); addParentNamespaces((Element) copy, namespacesNode.getParent()); } return xmlToText(copy); }
public static String getNamespaceURI(Node node) { if (node instanceof Element) { Namespace ns = ((Element) node).getNamespace(); if (ns != null) { String uri = ns.getURI(); if (uri == null || uri.length() == 0) { String uriAttr = ns.getPrefix().equals("") ? ((Element) node).getAttributeValue("xmlns") : null; if (uriAttr != null) { return uriAttr; } else { return getNamespaceURI(((Element) node).getParent()); } } else { return uri; } } } return null; }
public static String getNamespaceURI(Node node) { if (node instanceof Element) { Namespace ns = ((Element) node).getNamespace(); if (ns != null) { String uri = ns.getURI(); if (uri == null || uri.length() == 0) { String uriAttr = ns.getPrefix().equals("") ? ((Element) node).getAttributeValue("xmlns") : null; if (uriAttr != null) { return uriAttr; } else { return getNamespaceURI(((Element) node).getParent()); } } else { return uri; } } } return null; }
public static String nodeWithNamespacesToText(Node parseNode, Element namespacesNode) throws IOException { // we need to add any namespace prefixes defined in the root directory Node copy = parseNode.copy(); if (copy instanceof Element && parseNode instanceof Element) { moveCommentsIntoDescriptionElements((Element) copy, (Element) parseNode); addParentNamespaces((Element) copy, namespacesNode.getParent()); } return xmlToText(copy); }
public static void addParentNamespaces(Element element, Parent parent) { if (parent instanceof Element) { for (Attribute attr : ((Element) parent).getAttributes()) { String name = attr.getName(); if (name.startsWith("xmlns") && element.getAttributeValue(name) == null) { element.setAttribute(name, attr.getValue()); } } addParentNamespaces(element, ((Element) parent).getParent()); } }
public static void addParentNamespaces(Element element, Parent parent) { if (parent instanceof Element) { for (Attribute attr : ((Element) parent).getAttributes()) { String name = attr.getName(); if (name.startsWith("xmlns") && element.getAttributeValue(name) == null) { element.setAttribute(name, attr.getValue()); } } addParentNamespaces(element, ((Element) parent).getParent()); } }
Parent grandParent = root.getParent(); if (grandParent != null) { grandParent.addNode(grandParent.nodeIndexOf(root), c);
Parent grandParent = root.getParent(); if (grandParent != null) { grandParent.addNode(grandParent.nodeIndexOf(root), c);