/** * Removes the android namespace from all nodes. */ public void clearNodeNamespaces() { clearNodeNamespaces(getRootNode().getXml()); }
/** * Removes the android namespace from an element recursively. * * @param element the element */ private void clearNodeNamespaces(Element element) { String androidPrefix = XmlUtils.lookupNamespacePrefix(element, SdkConstants.ANDROID_URI); String name = element.getNodeName(); int colonIdx = name.indexOf(':'); if (colonIdx != -1) { String prefix = name.substring(0, colonIdx); if (prefix.equals(androidPrefix)) { String newName = name.substring(colonIdx + 1); getXml().renameNode(element, null, newName); } } NodeList childrenNodeList = element.getChildNodes(); for (int i = 0; i < childrenNodeList.getLength(); i++) { Node n = childrenNodeList.item(i); if (n instanceof Element) { clearNodeNamespaces((Element) n); } } } }
finalMergedDocument.clearNodeNamespaces();