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; /*//from w w w . java2s .c o m * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ 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 { /** * 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 GemFire 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; } }