Code example for Document

Methods: appendChild, createElementNS, createTextNode

0
      doc = db.newDocument();
    } catch (Exception ex) {
      throw new RuntimeException(ex);
    } 
 
    Element elem = doc.createElementNS(XMLNS_JBI_MGMT, "component-task-result");
    doc.appendChild(elem);
    Element compNameElem = doc.createElementNS(XMLNS_JBI_MGMT, "component-name");
    elem.appendChild(compNameElem);
    Element compTaskRsltDtlsElem = doc.createElementNS(XMLNS_JBI_MGMT, "component-task-result-details");
    elem.appendChild(compTaskRsltDtlsElem);
    Element taskRsltDtlsElem = doc.createElementNS(XMLNS_JBI_MGMT, "task-result-details");
    compTaskRsltDtlsElem.appendChild(taskRsltDtlsElem);
 
    Element taskId = doc.createElementNS(XMLNS_JBI_MGMT, "task-id");
    taskRsltDtlsElem.appendChild(taskId);
 
    Element taskResult = doc.createElementNS(XMLNS_JBI_MGMT, "task-result");
    taskRsltDtlsElem.appendChild(taskResult);
 
    // Why do I have to tell this thing the component name? It /knows/ the 
    // component name.... 
    compNameElem.appendChild(doc.createTextNode(_ode.getContext().getComponentName()));
 
    // And why on earth do I have to tell my caller the method he just 
    // called? 
    taskId.appendChild(doc.createTextNode(task));
 
    taskResult.appendChild(doc.createTextNode(status));
    return DOMUtils.domToString(elem);
  } 
}