Java XML Node Parse parseOptionString(Node node)

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

Description

parse Option String

License

Open Source License

Declaration

public static String parseOptionString(Node node) 

Method Source Code

//package com.java2s;

import java.util.Objects;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

public class Main {
    public static String parseOptionString(Node node) {
        Node str = parseOptionNode(node);
        if (str == null) {
            return null;
        } else {//from   w ww. jav a2 s  .co  m
            return parseString(str);
        }
    }

    public static Node parseOptionNode(Node node) {
        Objects.requireNonNull(node);

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

        Element e = (Element) node;
        if (e.hasAttribute("val")) {
            String val = e.getAttribute("val");
            if (val.equalsIgnoreCase("some")) {
                if (!e.hasChildNodes()) {
                    throw new IllegalArgumentException(
                            "Doesn't have children: " + e);
                }
                return e.getFirstChild();
            } else {
                return null;
            }
        } else {
            return null;
        }
    }

    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. parseInt(Node node)
  2. parseIntervals(Node intervals)
  3. parseList(Node node)
  4. parseModule(Node module, PrintWriter out)
  5. parseOptionNode(Node node)
  6. parsePairFirst(Node node)
  7. parseProperties(Node doc)
  8. parseProtoypes(Node module, Node iFace, PrintWriter out)
  9. parsePseudoHTML(Node e, StringBuffer html)