Java XML Node Text Value getNamedItemText(NamedNodeMap map, String name)

Here you can find the source of getNamedItemText(NamedNodeMap map, String name)

Description

Gets the actual text from a named item contained in the given node map.

License

Apache License

Parameter

Parameter Description
map the node map to get the named item from;
name the name of the item to get.

Return

the text of the named item, can be null in case the named item does not exist, or has no text.

Declaration

private static String getNamedItemText(NamedNodeMap map, String name) 

Method Source Code

//package com.java2s;
/*//from   w ww  .  ja v  a2 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 {
    /**
     * Gets the actual text from a named item contained in the given node map.
     * 
     * @param map
     *            the node map to get the named item from;
     * @param name
     *            the name of the item to get.
     * @return the text of the named item, can be <code>null</code> in case the named item does not exist, or has no
     *         text.
     */
    private static String getNamedItemText(NamedNodeMap map, String name) {
        Node namedItem = map.getNamedItem(name);
        if (namedItem == null) {
            return null;
        } else {
            return namedItem.getTextContent();
        }
    }
}

Related

  1. getFirstExtensionNode(Node extensionsNode)
  2. getFirstExtensionNodeFromWorkingSet(Node extensionsNode, String workingSetName)
  3. getFirstLevelTextContent(Node node)
  4. getFirstSubElementsInnerText(Node element, String subElementName)
  5. getInnerXmlText(Node xmlNode)
  6. getNamespaceURIFromPrefix(Node context, String prefix)
  7. getNamespaceURIFromPrefix(Node context, String prefix)
  8. getNodeText(final Node node)
  9. getNodeText(Node node)