Example usage for org.w3c.dom Attr getFirstChild

List of usage examples for org.w3c.dom Attr getFirstChild

Introduction

In this page you can find the example usage for org.w3c.dom Attr getFirstChild.

Prototype

public Node getFirstChild();

Source Link

Document

The first child of this node.

Usage

From source file:org.sakaiproject.tool.assessment.qti.util.XmlStringBuffer.java

/**
 * xpath lookup/*from  ww w.  ja  v  a2s.c o m*/
 *
 * @param xpath
 * @param type
 *
 * @return value
 */
public String selectSingleValue(String xpath, String type) {
    // user passes the if its an element or attribute
    String value = null;
    List list = this.selectNodes(xpath);
    if (list != null) {
        int no = list.size();

        if (list.size() > 0) {
            if ((type != null) && type.equals("element")) {
                Element element = (Element) list.get(0);

                CharacterData elementText = (CharacterData) element.getFirstChild();
                Integer getTime = null;
                if ((elementText != null) && (elementText.getNodeValue() != null)
                        && (elementText.getNodeValue().trim().length() > 0)) {
                    value = elementText.getNodeValue();
                }
            }

            if ((type != null) && type.equals("attribute")) {
                Attr attr = (Attr) list.get(0);

                CharacterData elementText = (CharacterData) attr.getFirstChild();

                Integer getTime = null;
                if ((elementText != null) && (elementText.getNodeValue() != null)
                        && (elementText.getNodeValue().trim().length() > 0)) {
                    value = elementText.getNodeValue();
                }
            }
        }
    }

    return value;
}