Java XML Attribute from Element getStringAttr(Element element, String name, String def)

Here you can find the source of getStringAttr(Element element, String name, String def)

Description

get String Attr

License

Apache License

Declaration

public static String getStringAttr(Element element, String name, String def) 

Method Source Code

//package com.java2s;
/*/*from  w  ww.j  ava2s.co  m*/
 * Copyright 2017 Andrey Timofeev.
 *
 * Licensed 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.Element;

public class Main {
    public static String getStringAttr(Element element, String name) {
        String attr = element.getAttribute(name);
        return attr;
    }

    public static String getStringAttr(Element element, String name, String def) {
        String attr = element.getAttribute(name);
        if (attr.isEmpty()) {
            attr = def;
        }
        return attr;
    }
}

Related

  1. getIntAttributeIgnoreCase(Element ele, String attr, int defaultvalue)
  2. getIntAttributeValue(Element element, String attribute)
  3. getInteger(final org.w3c.dom.Element element, final String attr, int def)
  4. getIntegerAttribute(Element el, String attribute)
  5. getIntegerAttribute(Element element, String name)
  6. getStringAttribute(Element e, String name, String def)
  7. getStringAttribute(Element el, String attribute)
  8. getStringAttributeValue(Element element, String attribute)
  9. getStringAttributeValue(final Element element, final String attributeName)