Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

public class Main {
    /**
     * Helper function for quickly retrieving an attribute from a given
     * element. 
     * @param ele The document element from which to pull the attribute value.
     * @param attrName The name of the attribute.
     * @return The value of the attribute contained within the element
     */
    public static String getAttributeValue(Element ele, String attrName) {
        return decode(ele.getAttribute(attrName));
    }

    /**
     * Helper function for decode XML entities.
     * @param str The XML-encoded String to decode.
     * @return An XML-decoded String.
     */
    public static String decode(String str) {

        if (str == null) {
            return null;
        }

        str = str.replaceAll(">", ">");
        str = str.replaceAll("&lt;", "<");
        str = str.replaceAll("&quot;", "\"");
        str = str.replaceAll("&amp;", "&");

        return str;
    }
}