Java XML Node Parse parseStringIdList(Node e)

Here you can find the source of parseStringIdList(Node e)

Description

parse String Id List

License

Open Source License

Declaration

public static final String[] parseStringIdList(Node e) throws Exception 

Method Source Code

//package com.java2s;
/*//from w ww  .j  av a 2  s .  c  om
 *    ALMA - Atacama Large Millimiter Array
 *    (c) European Southern Observatory, 2002
 *    Copyright by ESO (in the framework of the ALMA collaboration),
 *                 and Cosylab
 *    All rights reserved
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation; either
 *    version 2.1 of the License, or (at your option) any later version.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA 02111-1307  USA
 */

import org.w3c.dom.Node;

public class Main {
    public static final String[] parseStringIdList(Node e) throws Exception {
        if (e == null || e.getNodeType() != Node.ELEMENT_NODE || !e.getNodeName().equals("id-list"))
            throw new IllegalArgumentException();

        Node cur = e.getFirstChild();
        int count = 0;

        while (cur != null) {
            if (cur.getNodeType() != Node.ELEMENT_NODE)
                throw new Exception("<id-list> contains an unknown child");
            if (!cur.getNodeName().equals("id"))
                throw new Exception("<id-list> contains an unknown child");

            Node kid = cur.getFirstChild();
            if (kid == null)
                throw new Exception("<id> doesn't contain a value");
            if (kid.getNodeType() != Node.TEXT_NODE)
                throw new Exception("<id> can only contain text");
            if (kid.getNextSibling() != null)
                throw new Exception("<id> can only contain text");

            count++;
            cur = cur.getNextSibling();
        }

        String[] result = new String[count];

        cur = e.getFirstChild();
        int pos = 0;

        while (cur != null) {
            result[pos++] = cur.getFirstChild().getNodeValue();

            cur = cur.getNextSibling();
        }

        return result;
    }
}

Related

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