Java XML Node Parse parseStringList(Node node)

Here you can find the source of parseStringList(Node node)

Description

parse String List

License

Open Source License

Declaration

public static List<String> parseStringList(Node node) 

Method Source Code

//package com.java2s;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import org.w3c.dom.Node;

public class Main {
    public static List<String> parseStringList(Node node) {
        List<Node> nodes = parseList(node);

        List<String> strings = new ArrayList<>(nodes.size());
        for (Node child : nodes) {
            strings.add(parseString(child));
        }//from   ww w.j a v  a2  s.  co  m
        return strings;
    }

    public static List<Node> parseList(Node node) {
        Objects.requireNonNull(node);

        if (!node.getNodeName().equalsIgnoreCase("list")) {
            throw new IllegalArgumentException("Node is not list: " + node);
        }

        int n = node.getChildNodes().getLength();
        List<Node> nodes = new ArrayList<>(n);
        for (int i = 0; i < n; i++) {
            nodes.add(node.getChildNodes().item(i));
        }
        return nodes;
    }

    public static String parseString(Node node) {
        Objects.requireNonNull(node);

        if (!node.getNodeName().equalsIgnoreCase("string")) {
            throw new IllegalArgumentException("Node is not string: "
                    + node);
        }

        return node.getTextContent();
    }
}

Related

  1. parseProperties(Node doc)
  2. parseProtoypes(Node module, Node iFace, PrintWriter out)
  3. parsePseudoHTML(Node e, StringBuffer html)
  4. parseSpelling(Node spelling)
  5. parseStringIdList(Node e)