Example usage for org.w3c.dom CharacterData setNodeValue

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

Introduction

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

Prototype

public void setNodeValue(String nodeValue) throws DOMException;

Source Link

Document

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

Usage

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

/**
 * Set field entry./*w  w  w.  j a v  a2  s. c om*/
 *
 * @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);
    }
}