Here you can find the source of buildNamespacePrefixMap(final Element root)
Parameter | Description |
---|---|
root | Element to get namespaces and prefixes from. |
private static final Map<String, String> buildNamespacePrefixMap(final Element root)
//package com.java2s; import java.util.HashMap; import java.util.Map; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; public class Main { /**//from www . ja v a 2 s.com * Build {@link Map} of namespace URIs to prefixes. * * @param root * {@link Element} to get namespaces and prefixes from. * @return {@link Map} of namespace URIs to prefixes. * @since 8.1 */ private static final Map<String, String> buildNamespacePrefixMap(final Element root) { final HashMap<String, String> namespacePrefixMap = new HashMap<>(); //Look for all of the attributes of cache that start with //xmlns NamedNodeMap attributes = root.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Node item = attributes.item(i); if (item.getNodeName().startsWith("xmlns")) { //Anything after the colon is the prefix //eg xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" //has a prefix of xsi String[] splitName = item.getNodeName().split(":"); String prefix; if (splitName.length > 1) { prefix = splitName[1]; } else { prefix = ""; } String uri = item.getTextContent(); namespacePrefixMap.put(uri, prefix); } } return namespacePrefixMap; } }