private void addNamespace(String prefix, String namespaceURI, SAXElement element) { if (prefix == null || namespaceURI == null) { // No namespace. Ignore... return; } else if(prefix.equals(XMLConstants.DEFAULT_NS_PREFIX) && namespaceURI.equals(XMLConstants.NULL_NS_URI)) { // No namespace. Ignore... return; } else { String prefixNS = element.getAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, prefix); if(prefixNS != null && prefixNS.length() != 0) { // Already declared (on the element)... return; } } Attributes attributes = element.getAttributes(); AttributesImpl attributesCopy = new AttributesImpl(); attributesCopy.setAttributes(attributes); if(prefix.length() > 0) { attributesCopy.addAttribute(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, prefix, "xmlns:" + prefix, null, namespaceURI); } else { attributesCopy.addAttribute(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, prefix, "xmlns", null, namespaceURI); } element.setAttributes(attributesCopy); } }
private void addNamespace(String prefix, String namespaceURI, SAXElement element) { if (prefix == null || namespaceURI == null) { // No namespace. Ignore... return; } else if(prefix.equals(XMLConstants.DEFAULT_NS_PREFIX) && namespaceURI.equals(XMLConstants.NULL_NS_URI)) { // No namespace. Ignore... return; } else { String prefixNS = element.getAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, prefix); if(prefixNS != null && prefixNS.length() != 0) { // Already declared (on the element)... return; } } Attributes attributes = element.getAttributes(); AttributesImpl attributesCopy = new AttributesImpl(); attributesCopy.setAttributes(attributes); if(prefix.length() > 0) { attributesCopy.addAttribute(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, prefix, "xmlns:" + prefix, null, namespaceURI); } else { attributesCopy.addAttribute(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, prefix, "xmlns", null, namespaceURI); } element.setAttributes(attributesCopy); } }