Here you can find the source of getStringDataAsList(Document vastDoc, String elementName)
static List<String> getStringDataAsList(Document vastDoc,
String elementName)
//package com.java2s; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { static List<String> getStringDataAsList(Document vastDoc, String elementName) { return getStringDataAsList(vastDoc, elementName, null, null); }// w ww. jav a2 s . c o m static List<String> getStringDataAsList(Document vastDoc, String elementName, String attributeName, String attributeValue) { ArrayList<String> results = new ArrayList(); if (vastDoc != null) { NodeList nodes = vastDoc.getElementsByTagName(elementName); if (nodes != null) { int i = 0; while (i < nodes.getLength()) { Node node = nodes.item(i); if (node != null) { if (nodeMatchesAttributeFilter( node, attributeName, Arrays.asList(new String[] { attributeValue }))) { String nodeValue = getNodeValue(node); if (nodeValue != null) { results.add(nodeValue); } } } i++; } } } return results; } static boolean nodeMatchesAttributeFilter(Node node, String attributeName, List<String> attributeValues) { if (attributeName == null || attributeValues == null) { return true; } NamedNodeMap attrMap = node.getAttributes(); if (attrMap != null) { Node attrNode = attrMap.getNamedItem(attributeName); if (attrNode != null && attributeValues.contains(attrNode.getNodeValue())) { return true; } } return false; } static String getNodeValue(Node node) { return (node == null || node.getFirstChild() == null || node .getFirstChild().getNodeValue() == null) ? null : node .getFirstChild().getNodeValue().trim(); } }