Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import org.w3c.dom.Attr;

import org.w3c.dom.Node;

public class Main {
    public static int getAlternativeIdCount(Node xmlSubstanceNode, boolean includeEmpty) {
        int idCnt = 0;
        int maxID = xmlSubstanceNode.getAttributes().getLength();
        for (int i = 1; i < maxID; i++) {
            Attr oAlternative = (Attr) xmlSubstanceNode.getAttributes().getNamedItem("name" + i);
            if (oAlternative != null) {
                String value = oAlternative.getNodeValue();
                if (includeEmpty || (value != null && value.length() > 0))
                    idCnt++;
            }
        }
        return idCnt;
    }
}