@Test public void testFixNamespaceDeclarations() { System.out.println("===[ testFixNamespaceDeclarations ]==="); Document doc = DOMUtil.parseFile(FIX_NAMESPACE_FILENAME); System.out.println("Original XML:"); System.out.println(DOMUtil.serializeDOMToString(doc)); Element root = DOMUtil.getFirstChildElement(doc); Element target = (Element) root.getElementsByTagNameNS(DEFAULT_NS, "target").item(0); DOMUtil.fixNamespaceDeclarations(target); System.out.println("Fixed namespaces (doc):"); System.out.println(DOMUtil.serializeDOMToString(doc)); System.out.println("Fixed namespaces (target):"); System.out.println(DOMUtil.serializeDOMToString(target)); Map<String, String> decls = DOMUtil.getNamespaceDeclarations(target); assertEquals("bar decl", "http: assertEquals("foo decl", "http: assertEquals("default decl", "http: }
public static void fixNamespaceDeclarations(Element element) { fixNamespaceDeclarations(element, element); }
DOMUtil { public static void fixNamespaceDeclarations(Element element) { fixNamespaceDeclarations(element, element); } }
DOMUtil { public static void fixNamespaceDeclarations(Element element) { fixNamespaceDeclarations(element, element); }  }
DOMUtil { public static void fixNamespaceDeclarations(Element element) { fixNamespaceDeclarations(element, element); }  static String serializeDOMToString(org.w3c.dom.Node node); static void serializeDOMToFile(org.w3c.dom.Node node, File file); static Document getDocument(Node node); static Document getDocument(); static Document getDocument(QName rootElementName); static DocumentBuilder createDocumentBuilder(); static Document parseDocument(String doc); static Document parseFile(String filePath); static Document parseFile(File file); static Document parse(InputStream inputStream); static String showDom(List<Element> elements); static StringBuffer printDom(Node node); static StringBuffer printDom(Node node, boolean indent, boolean omitXmlDeclaration); static Node getNextSiblingElement(Node node); static Element getFirstChildElement(Node parent); static Element getLastChildElement(Node parent); static List<Element> getChildElements(Element element, QName elementName); @NotNull static List<Element> listChildElements(Node node); static boolean hasChildElements(Node node); static QName resolveQName(Element element); static QName resolveQName(Node domNode, String qnameStringRepresentation); static String findNamespace(Node domNode, String prefix); static QName resolveXsiType(Element element); static boolean hasXsiType(Element element); static void removeXsiType(Element element); static void setXsiType(Element element, QName type); static void setQNameAttribute(Element element, QName attributeName, QName attributeValue); static void setQNameAttribute(Element element, String attributeName, QName attributeValue); static void setQNameAttribute(Element element, QName attributeName, QName attributeValue,
			Element definitionElement); static void setQNameAttribute(Element element, String attributeName, QName attributeValue,
			Element definitionElement); static void setQNameValue(Element element, QName elementValue); static String lookupOrCreateNamespaceDeclaration(Element element, String namespaceUri,
			String preferredPrefix, Element definitionElement, boolean allowUseOfDefaultNamespace); static boolean isNamespaceDefinition(Attr attr); static void setNamespaceDeclaration(Element element, String prefix, String namespaceUri); static Map<String,String> getNamespaceDeclarations(Element element); static void setNamespaceDeclarations(Element element, Map<String, String> rootNamespaceDeclarations); static Map<String,String> getAllVisibleNamespaceDeclarations(Node node); static void fixNamespaceDeclarations(Element element); static boolean isPrefixUsed(Element targetElement, String prefix); static boolean hasNamespaceDeclarationForPrefix(Element targetElement, String prefix); static String getNamespaceDeclarationForPrefix(Element targetElement, String prefix); static String getNamespaceDeclarationPrefix(Attr attr); static String getNamespaceDeclarationNamespace(Attr attr); static Collection<Attr> listApplicationAttributes(Element element); static boolean hasApplicationAttributes(Element element); static Element getChildElement(Element element, QName qname); static Element getChildElement(Element element, String localPart); static Element getChildElement(Element element, int index); static Element getOrCreateAsFirstElement(Element parentElement, QName elementQName); @NotNull static QName getQName(Element element); static QName getQName(Node node); static QName getQNameValue(Element element); static QName getQNameAttribute(Element element, String attributeName); static QName getQNameAttribute(Element element, QName attributeName); static QName getQNameValue(Attr attr); static Integer getIntegerValue(Element element); static void copyContent(Element source, Element destination); static Element createElement(QName qname); static Element createElement(Document document, QName qname); static Element createElement(Document document, QName qname, Element parentElement,
			Element definitionElement); static Element createSubElement(Element parent, QName subElementQName); static boolean compareElement(Element a, Element b, boolean considerNamespacePrefixes); static boolean compareElement(Element a, Element b, boolean considerNamespacePrefixes, boolean considerWhitespaces); static boolean compareDocument(Document a, Document b, boolean considerNamespacePrefixes, boolean considerWhitespaces); static boolean compareElementList(List<Element> aList, List<Element> bList, boolean considerNamespacePrefixes); static boolean compareElementList(List<Element> aList, List<Element> bList, boolean considerNamespacePrefixes, boolean considerWhitespaces); static boolean compareTextNodeValues(String a, String b); static boolean compareTextNodeValues(String a, String b, boolean considerWhitespaces); static void normalize(Node node, boolean keepWhitespaces); static boolean isJunk(Node node); static void validateNonEmptyQName(QName qname, String shortDescription, boolean allowEmptyNamespace); static Element findElementRecursive(Element element, QName elementQName); static QName getQNameWithoutPrefix(Node node); static boolean isElementName(Element element, QName name); static boolean isNil(Element element); static void setNill(Element element); static String serializeElementContent(Element element); static boolean isEmpty(Element element); static boolean isEmpty(Attr attr); static void setAttributeValue(Element element, String name, String value); static void setElementTextContent(Element element, String value); static void checkValidXmlChars(String stringValue); static void createComment(Element element, String text); static String getAttribute(Element element, QName attrQname); static boolean hasNoPrefix(Element top); @NotNull static List<Element> getElementsWithoutNamespacePrefix(Element element); }
DOMUtil { public static void fixNamespaceDeclarations(Element element) { fixNamespaceDeclarations(element, element); }  static String serializeDOMToString(org.w3c.dom.Node node); static void serializeDOMToFile(org.w3c.dom.Node node, File file); static Document getDocument(Node node); static Document getDocument(); static Document getDocument(QName rootElementName); static DocumentBuilder createDocumentBuilder(); static Document parseDocument(String doc); static Document parseFile(String filePath); static Document parseFile(File file); static Document parse(InputStream inputStream); static String showDom(List<Element> elements); static StringBuffer printDom(Node node); static StringBuffer printDom(Node node, boolean indent, boolean omitXmlDeclaration); static Node getNextSiblingElement(Node node); static Element getFirstChildElement(Node parent); static Element getLastChildElement(Node parent); static List<Element> getChildElements(Element element, QName elementName); @NotNull static List<Element> listChildElements(Node node); static boolean hasChildElements(Node node); static QName resolveQName(Element element); static QName resolveQName(Node domNode, String qnameStringRepresentation); static String findNamespace(Node domNode, String prefix); static QName resolveXsiType(Element element); static boolean hasXsiType(Element element); static void removeXsiType(Element element); static void setXsiType(Element element, QName type); static void setQNameAttribute(Element element, QName attributeName, QName attributeValue); static void setQNameAttribute(Element element, String attributeName, QName attributeValue); static void setQNameAttribute(Element element, QName attributeName, QName attributeValue,
			Element definitionElement); static void setQNameAttribute(Element element, String attributeName, QName attributeValue,
			Element definitionElement); static void setQNameValue(Element element, QName elementValue); static String lookupOrCreateNamespaceDeclaration(Element element, String namespaceUri,
			String preferredPrefix, Element definitionElement, boolean allowUseOfDefaultNamespace); static boolean isNamespaceDefinition(Attr attr); static void setNamespaceDeclaration(Element element, String prefix, String namespaceUri); static Map<String,String> getNamespaceDeclarations(Element element); static void setNamespaceDeclarations(Element element, Map<String, String> rootNamespaceDeclarations); static Map<String,String> getAllVisibleNamespaceDeclarations(Node node); static void fixNamespaceDeclarations(Element element); static boolean isPrefixUsed(Element targetElement, String prefix); static boolean hasNamespaceDeclarationForPrefix(Element targetElement, String prefix); static String getNamespaceDeclarationForPrefix(Element targetElement, String prefix); static String getNamespaceDeclarationPrefix(Attr attr); static String getNamespaceDeclarationNamespace(Attr attr); static Collection<Attr> listApplicationAttributes(Element element); static boolean hasApplicationAttributes(Element element); static Element getChildElement(Element element, QName qname); static Element getChildElement(Element element, String localPart); static Element getChildElement(Element element, int index); static Element getOrCreateAsFirstElement(Element parentElement, QName elementQName); @NotNull static QName getQName(Element element); static QName getQName(Node node); static QName getQNameValue(Element element); static QName getQNameAttribute(Element element, String attributeName); static QName getQNameAttribute(Element element, QName attributeName); static QName getQNameValue(Attr attr); static Integer getIntegerValue(Element element); static void copyContent(Element source, Element destination); static Element createElement(QName qname); static Element createElement(Document document, QName qname); static Element createElement(Document document, QName qname, Element parentElement,
			Element definitionElement); static Element createSubElement(Element parent, QName subElementQName); static boolean compareElement(Element a, Element b, boolean considerNamespacePrefixes); static boolean compareElement(Element a, Element b, boolean considerNamespacePrefixes, boolean considerWhitespaces); static boolean compareDocument(Document a, Document b, boolean considerNamespacePrefixes, boolean considerWhitespaces); static boolean compareElementList(List<Element> aList, List<Element> bList, boolean considerNamespacePrefixes); static boolean compareElementList(List<Element> aList, List<Element> bList, boolean considerNamespacePrefixes, boolean considerWhitespaces); static boolean compareTextNodeValues(String a, String b); static boolean compareTextNodeValues(String a, String b, boolean considerWhitespaces); static void normalize(Node node, boolean keepWhitespaces); static boolean isJunk(Node node); static void validateNonEmptyQName(QName qname, String shortDescription, boolean allowEmptyNamespace); static Element findElementRecursive(Element element, QName elementQName); static QName getQNameWithoutPrefix(Node node); static boolean isElementName(Element element, QName name); static boolean isNil(Element element); static void setNill(Element element); static String serializeElementContent(Element element); static boolean isEmpty(Element element); static boolean isEmpty(Attr attr); static void setAttributeValue(Element element, String name, String value); static void setElementTextContent(Element element, String value); static void checkValidXmlChars(String stringValue); static void createComment(Element element, String text); static String getAttribute(Element element, QName attrQname); static boolean hasNoPrefix(Element top); @NotNull static List<Element> getElementsWithoutNamespacePrefix(Element element); static final Trace LOGGER; static final String W3C_XML_SCHEMA_XMLNS_URI; static final String W3C_XML_SCHEMA_XMLNS_PREFIX; static final String W3C_XML_XML_URI; static final String W3C_XML_XML_PREFIX; static final String NS_W3C_XSI_PREFIX; static final QName XSI_TYPE; static final QName XSI_NIL; static final QName XML_ID_ATTRIBUTE; static final String HACKED_XSI_TYPE; static final String IS_LIST_ATTRIBUTE_NAME; static final String NS_W3C_XML_SCHEMA_PREFIX; static final QName XSD_SCHEMA_ELEMENT; static final QName XSD_ANNOTATION_ELEMENT; static final QName XSD_APPINFO_ELEMENT; static final QName XSD_DOCUMENTATION_ELEMENT; static final QName XSD_IMPORT_ELEMENT; static final QName XSD_INCLUDE_ELEMENT; static final QName XSD_ATTR_TARGET_NAMESPACE; static final QName XSD_ATTR_NAMESPACE; static final QName XSD_ATTR_SCHEMA_LOCATION; static final QName XSD_DECIMAL; static final QName XSD_STRING; static final QName XSD_INTEGER; static final QName XSD_INT; static final QName XSD_LONG; static final QName XSD_SHORT; static final QName XSD_FLOAT; static final QName XSD_DOUBLE; static final QName XSD_BOOLEAN; static final QName XSD_BASE64BINARY; static final QName XSD_DATETIME; static final QName XSD_DURATION; static final QName XSD_BYTE; static final QName XSD_QNAME; static final QName XSD_ANYURI; static final QName XSD_ANY; static final QName XSD_ANYTYPE; static final String NS_XML_ENC; static final String NS_XML_DSIG; static final String NS_WSDL; static final String NS_WSDL_SCHEMA_PREFIX; static final QName WSDL_IMPORT_ELEMENT; static final QName WSDL_TYPES_ELEMENT; static final QName WSDL_ATTR_NAMESPACE; static final QName WSDL_ATTR_SCHEMA_LOCATION; static final QName WSDL_ATTR_LOCATION; }