Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    public static String[] getStringValuesForXMLTag(Element xmlElement, String key) {
        NodeList nl = xmlElement.getElementsByTagName(key);

        if (nl.getLength() > 0) {

            String[] output = new String[nl.getLength()];

            for (int i = 0; i < nl.getLength(); i++) {
                Node node = nl.item(i).getFirstChild();
                if (node != null) {
                    output[i] = node.getNodeValue().trim();
                }
            }
            return output;
        }
        return null;
    }
}