public static void copyNSContext(Element source, Element dest) { Map<String, String> sourceNS = getParentNamespaces(source); sourceNS.putAll(getMyNamespaces(source)); Map<String, String> destNS = getParentNamespaces(dest); destNS.putAll(getMyNamespaces(dest)); // (source - dest) to avoid adding twice the same ns on dest for (String pr : destNS.keySet()) sourceNS.remove(pr); for (Map.Entry<String, String> entry : sourceNS.entrySet()) { String prefix = entry.getKey(); String uri = entry.getValue(); if (prefix == null || "".equals(prefix)) dest.setAttributeNS(DOMUtils.NS_URI_XMLNS, "xmlns", uri); else dest.setAttributeNS(DOMUtils.NS_URI_XMLNS, "xmlns:"+ prefix, uri); } }
Map<String,String> mine = getMyNamespaces(el); Node n = el.getParentNode(); while (n != null && n.getNodeType() != Node.DOCUMENT_NODE) {
/** * Construct a {@link NSContext} instance for the supplied element. * @param el the <code>Element</code> to gather the namespace context for * @return the <code>NSContext</code> */ public static NSContext getMyNSContext(Element el) { NSContext ns = new NSContext(); ns.register(getParentNamespaces(el)); ns.register(getMyNamespaces(el)); return ns; }
injectNamespaces(omElement,nscontext.toMap()); } else { Map<String,String> nss = DOMUtils.getMyNamespaces(src); injectNamespaces(omElement, nss);