Example usage for org.w3c.dom CharacterData getNodeValue

List of usage examples for org.w3c.dom CharacterData getNodeValue

Introduction

In this page you can find the example usage for org.w3c.dom CharacterData getNodeValue.

Prototype

public String getNodeValue() throws DOMException;

Source Link

Document

The value of this node, depending on its type; see the table above.

Usage

From source file:Main.java

public static String getCharacterDataFromDocumentWithKey(final Document document, final String key) {
    String result = null;/*from w  w w  . jav a  2s  .c  o  m*/
    if (document != null) {
        final NodeList jobNodeList = document.getElementsByTagName(key);
        final CharacterData characterData = (CharacterData) jobNodeList.item(0).getChildNodes().item(0);
        result = characterData.getNodeValue();

    }
    return result;
}

From source file:Main.java

public static String getCharacterDataFromElementWithKey(final Element element, final String key) {
    String result = null;//  w w w .j  a v a 2  s  .  com
    if (element != null) {
        final NodeList jobNodeList = element.getElementsByTagName(key);

        final Node node = jobNodeList.item(0);
        if (node != null) {
            final CharacterData characterData = (CharacterData) jobNodeList.item(0).getChildNodes().item(0);
            if (characterData != null) {
                result = characterData.getNodeValue();
            }
        }
    }
    return result;
}

From source file:org.sakaiproject.tool.assessment.qti.asi.ASIBaseClass.java

/**
 * DOCUMENTATION PENDING/*from www  .ja  va  2s  .  c  o  m*/
 *
 * @param xpath DOCUMENTATION PENDING
 *
 * @return DOCUMENTATION PENDING
 */
protected String getFieldentry(String xpath) {
    if (log.isDebugEnabled()) {
        log.debug("getFieldentry(String " + xpath + ")");
    }

    String val = null;
    int no = 0;

    List metadataList;
    try {
        metadataList = this.selectNodes(xpath);
        no = metadataList.size();

        if (metadataList.size() > 0) {
            Document document = this.getDocument();
            Element fieldentry = (Element) metadataList.get(0);
            CharacterData fieldentryText = (CharacterData) fieldentry.getFirstChild();

            Integer getTime = null;
            if ((fieldentryText != null) && (fieldentryText.getNodeValue() != null)
                    && (fieldentryText.getNodeValue().trim().length() > 0)) {
                val = fieldentryText.getNodeValue();
            }
        }
    } catch (DOMException ex) {
        log.error(ex.getMessage(), ex);
    }

    catch (Exception ex) {
        log.error(ex.getMessage(), ex);
    }

    return val;
}

From source file:org.sakaiproject.tool.assessment.qti.asi.ASIBaseClass.java

/**
 * Set field entry.//  ww w .ja  va  2 s .  co  m
 *
 * @param xpath
 * @param setValue
 * @param noEscapeXML
 */
protected void setFieldentry(String xpath, String value, boolean noEscapeXML) {
    String setValue = null;

    if (noEscapeXML) {
        setValue = value;
    } else {
        setValue = escapeXml(value);
    }

    if (log.isDebugEnabled()) {
        log.debug("setFieldentry(String " + xpath + ", String " + setValue + ")");
    }

    List metadataList;
    try {
        metadataList = this.selectNodes(xpath);
        int no = metadataList.size();
        String val = null;

        if (metadataList.size() > 0) {
            Document document = this.getDocument();
            Element fieldentry = (Element) metadataList.get(0);
            CharacterData fieldentryText = (CharacterData) fieldentry.getFirstChild();

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

            if (setValue != null) {
                if (fieldentryText == null) {
                    Text newElementText = fieldentry.getOwnerDocument().createTextNode(setValue);

                    fieldentry.appendChild(newElementText);
                    fieldentryText = (CharacterData) fieldentry.getFirstChild();
                } else {
                    fieldentryText.setNodeValue(setValue);
                }
            }
        }
    } catch (ParserConfigurationException e) {
        log.error(e.getMessage(), e);
    } catch (SAXException e) {
        log.error(e.getMessage(), e);
    } catch (IOException e) {
        log.error(e.getMessage(), e);
    }
}

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

/**
 * xpath lookup//from  ww w .j  ava 2 s  .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;
}