XMLUtils { public static Map<String, String> lookupNamespaces(Node referenceNode) { Map<String, String> namespaces = new HashMap<String, String>(); Node node; if (referenceNode.getNodeType() == Node.DOCUMENT_NODE) { node = referenceNode.getFirstChild(); } else { node = referenceNode; } if (node != null && node.hasAttributes()) { for (int i = 0; i < node.getAttributes().getLength(); i++) { Node attribute = node.getAttributes().item(i); if (attribute.getNodeName().startsWith(XMLConstants.XMLNS_ATTRIBUTE + ":")) { namespaces.put(attribute.getNodeName().substring((XMLConstants.XMLNS_ATTRIBUTE + ":").length()), attribute.getNodeValue()); } else if (attribute.getNodeName().startsWith(XMLConstants.XMLNS_ATTRIBUTE)) { namespaces.put(XMLConstants.DEFAULT_NS_PREFIX, attribute.getNodeValue()); } } } return namespaces; } private  XMLUtils(); static void initialize(XmlConfigurer xmlConfigurer); static LSParser createLSParser(); static LSSerializer createLSSerializer(); static LSInput createLSInput(); static LSOutput createLSOutput(); static Node findNodeByName(Document doc, String pathExpression); static void stripWhitespaceNodes(Node element); static String getNodesPathName(Node node); static String serialize(Document doc); static String prettyPrint(String xml); static Map<String, String> lookupNamespaces(Node referenceNode); static Document parseMessagePayload(String messagePayload); static Charset getTargetCharset(Document doc); static String omitXmlDeclaration(String xml); static boolean hasXmlPayload(Message message);  }
@Test public void testLookupNamespacesInXMLFragmentNoNamespacesFound() { Map<String, String> namespaces = NamespaceContextBuilder.lookupNamespaces("<testRequest id=\"123456789\"></testRequest>"); Assert.assertEquals(namespaces.size(), 0); }