Java XML Node Sibiling getSiblingValues(Node currentNode, Set siblingTags)

Here you can find the source of getSiblingValues(Node currentNode, Set siblingTags)

Description

This method looks at the siblings of a given node, matches the ones in the passed Set, then returns a map of the matches with their values

License

Open Source License

Parameter

Parameter Description
currentNode a parameter
siblingTags a Set of Strings containing the tagnames to look for

Return

Map of desired tag names to their values

Declaration

public static Map<String, String> getSiblingValues(Node currentNode,
        Set<String> siblingTags) 

Method Source Code

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

import java.util.HashMap;

import java.util.Map;
import java.util.Set;

import org.w3c.dom.Node;

public class Main {
    /**//ww w. ja v a2s.c  o m
     * This method looks at the siblings of a given node, matches the ones in the passed Set,
     * then returns a map of the matches with their values
     * 
     * @param currentNode
     * @param siblingTags   a Set of Strings containing the tagnames to look for
     * @return Map of desired tag names to their values
     */
    public static Map<String, String> getSiblingValues(Node currentNode,
            Set<String> siblingTags) {
        Map<String, String> responseMap = new HashMap<String, String>();
        String testString = currentNode.getLocalName().toLowerCase();
        for (String tagName : siblingTags) {
            if (testString.contains(tagName.toLowerCase())) {
                responseMap.put(tagName, currentNode.getTextContent()
                        .trim());
                return responseMap;
            }
        }

        return responseMap;
    }
}

Related

  1. getPreviousSibling(Node node, short nodeType)
  2. getPreviousSiblingByName(Node currentNode, String tagName)
  3. getPreviousSiblingElement(Node node)
  4. getPreviousSiblingElement(Node node)
  5. getSibling(Node current)