Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import org.w3c.dom.*;

import java.util.*;

public class Main {
    private static final String TAG_ATTR = "attr";

    public static void loadAttributesFromNode(Node node, Properties attrs) {
        attrs.clear();
        Element elem = (Element) node;
        NodeList list = elem.getElementsByTagName(TAG_ATTR);
        for (int i = 0; i < list.getLength(); i++) {
            String text = getTextTag(list.item(i));
            String[] s = text.split("=");
            if (s.length >= 2) {
                attrs.setProperty(s[0], s[1]);
            }
        }
    }

    public static String getTextTag(Node node) {
        Node child = node.getFirstChild();
        if (child.getNodeType() == Node.TEXT_NODE)
            return child.getNodeValue();
        return null;
    }

    public static String getTextTag(Node node, String tagName) {
        Element elem = (Element) node;
        NodeList list = elem.getElementsByTagName(tagName);
        if (list.getLength() == 0)
            return null;
        Node child = list.item(0).getFirstChild();
        if (child.getNodeType() == Node.TEXT_NODE)
            return child.getNodeValue();
        return null;
    }
}