Here you can find the source of getNSPrefixFromNSAttr(Attr a)
Parameter | Description |
---|---|
a | the Attr with the declaration (must be non-<code>null</code). |
""
if none was declared, e.g., xmlns="foo"
.
public static String getNSPrefixFromNSAttr(Attr a)
//package com.java2s; /*/* w w w. jav a 2 s.c om*/ * 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 org.w3c.dom.Attr; public class Main { /** The namespaceURI represented by the prefix <code>xmlns</code>. */ public static final String NS_URI_XMLNS = "http://www.w3.org/2000/xmlns/"; /** * Fetch the non-null namespace prefix from a {@link Attr} that declares * a namespace. (The DOM APIs will return <code>null</code> for a non-prefixed * declaration. * @param a the {@link Attr} with the declaration (must be non-<code>null</code). * @return the namespace prefix or <code>""</code> if none was * declared, e.g., <code>xmlns="foo"</code>. */ public static String getNSPrefixFromNSAttr(Attr a) { assert a != null; assert isNSAttribute(a); if (a.getPrefix() == null) { return ""; } return a.getName().substring(a.getPrefix().length() + 1); } /** * Test whether an attribute contains a namespace declaration. * @param a an {@link Attr} to test. * @return <code>true</code> if the {@link Attr} is a namespace declaration */ public static boolean isNSAttribute(Attr a) { assert a != null; String s = a.getNamespaceURI(); return (s != null && s.equals(NS_URI_XMLNS)); } }