Java XML Attribute Get getAttr(NamedNodeMap attrs, String name, String missing_err)

Here you can find the source of getAttr(NamedNodeMap attrs, String name, String missing_err)

Description

get Attr

License

Apache License

Declaration

public static String getAttr(NamedNodeMap attrs, String name,
            String missing_err) 

Method Source Code

//package com.java2s;
/**//from   w  w  w. j  a  v  a 2  s.  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 org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

public class Main {
    public static String getAttr(NamedNodeMap attrs, String name) {
        return getAttr(attrs, name, null);
    }

    public static String getAttr(Node nd, String name) {
        return getAttr(nd.getAttributes(), name);
    }

    public static String getAttr(NamedNodeMap attrs, String name,
            String missing_err) {
        Node attr = attrs == null ? null : attrs.getNamedItem(name);
        if (attr == null) {
            if (missing_err == null)
                return null;
            throw new RuntimeException(missing_err
                    + ": missing mandatory attribute '" + name + "'");
        }
        String val = attr.getNodeValue();
        return val;
    }

    public static String getAttr(Node node, String name, String missing_err) {
        return getAttr(node.getAttributes(), name, missing_err);
    }
}

Related

  1. getAttr(Element e, String name)
  2. getAttr(Element elem, String name)
  3. getAttr(final Node n, final String attr)
  4. getAttr(final Node n, final String attrName)
  5. getAttr(NamedNodeMap attrs, String name)
  6. getAttr(Node n, String name)
  7. getAttr(Node node, String attr)
  8. getAttr(Node node, String name)
  9. getAttr(Node node, String name, String defaultValue)