Java XML Attribute Read getOptionalAttributeValue(NamedNodeMap attrs, String name)

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

Description

get Optional Attribute Value

License

Apache License

Declaration

public static String getOptionalAttributeValue(NamedNodeMap attrs, String name) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright 2012 One Platform Foundation
 * /*  w  ww. ja  v a2s . c o m*/
 *    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.NamedNodeMap;
import org.w3c.dom.Node;

public class Main {
    public static String getOptionalAttributeValue(NamedNodeMap attrs, String name) {

        Node namedItem = attrs.getNamedItem(name);
        if (namedItem == null) {
            return "";
        } else {
            return namedItem.getTextContent();
        }
    }
}

Related

  1. getNewAttribute(Element element, String name)
  2. getNSPrefixFromNSAttr(Attr a)
  3. getNullableAttribute(final Element node, final String attributeName)
  4. getNullSafe(NamedNodeMap attr, String key)
  5. getOptionalAttribute(Element elt, String name)
  6. readAttribute(Node element, String attributeName)
  7. readAttribute(Node node, String attribute, String defaultValue)
  8. readAttributeWithPrefix(Node node, String attributePrefix, String defaultValue)
  9. readBoolAttr(Element element, String attributeName)