Java XML Attribute Get getAttributeNSOrNull(Element e, String name, String nsURI)

Here you can find the source of getAttributeNSOrNull(Element e, String name, String nsURI)

Description

get Attribute NS Or Null

License

Open Source License

Declaration

public static String getAttributeNSOrNull(Element e, String name, String nsURI) 

Method Source Code


//package com.java2s;
/*//  ww w. ja  va  2 s  .c  o m
 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Oracle designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Oracle in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

import org.w3c.dom.Attr;
import org.w3c.dom.Element;

import javax.xml.namespace.QName;

public class Main {
    public static String getAttributeNSOrNull(Element e, String name, String nsURI) {
        Attr a = e.getAttributeNodeNS(nsURI, name);
        if (a == null)
            return null;
        return a.getValue();
    }

    public static String getAttributeNSOrNull(Element e, QName name) {
        Attr a = e.getAttributeNodeNS(name.getNamespaceURI(), name.getLocalPart());
        if (a == null)
            return null;
        return a.getValue();
    }

    public static String getLocalPart(String s) {
        int i = s.indexOf(':');
        if (i == -1)
            return s;
        return s.substring(i + 1);
    }
}

Related

  1. getAttributeNode(Node sNode, String attribName)
  2. getAttributeNodeList(Element element, Pattern name)
  3. getAttributeNS(Element el, String namespaceURI, String localPart)
  4. getAttributeNS(Element elem, String namespace, String att)
  5. getAttributeNSName(Element e, String attrName)
  6. getAttributeNSOrNull(Element e, String name, String nsURI)
  7. getAttributeOrNull(String attribute, Element element)
  8. getAttributePropertyFromElement(final Element element, final String attribute)
  9. getAttributes(Element el)