Java XML Attribute Get getAttributeContent(Node item, String attributeName)

Here you can find the source of getAttributeContent(Node item, String attributeName)

Description

Gets the content of an attribute.

License

Open Source License

Declaration

public static Optional<String> getAttributeContent(Node item, String attributeName) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Optional;

import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

public class Main {
    /**/*from   w  ww  .j  a v  a 2  s .  c om*/
     * Gets the content of an attribute.
     * For example,
     * <item attributeName="content" />
     */
    public static Optional<String> getAttributeContent(Node item, String attributeName) {
        NamedNodeMap attributes = item.getAttributes();
        return Optional.ofNullable(attributes.getNamedItem(attributeName)).map(Node::getTextContent);
    }
}

Related

  1. getAttributeByLocalName(XMLStreamReader reader, String localName)
  2. getAttributeByName(final List elements, final String attributeName)
  3. getAttributeByName(Node content, String attributeName)
  4. getAttributeByName(Node node, String name, boolean defaultValue)
  5. getAttributeByName(Node node, String name, String defaultValue)
  6. getAttributeEnum(Node node, String attributeName, Class enumClass)
  7. getAttributeFloatValue(String attribute, NamedNodeMap namedNodeMap)
  8. getAttributeFromClosestAncestorOfAnyKind(Node node, String attributeName)
  9. getAttributeIfExists(Node node, String name)