Code example for Element

Methods: appendChild, getOwnerDocument

0
    public void setPart(String partName, Element content) {
        Element message = getMessage();
        if (message == null) {
            Document doc = DOMUtils.newDocument();
            message = doc.createElement("message");
            doc.appendChild(message);
        } 
        message.appendChild(message.getOwnerDocument().importNode(content, true));
        setMessage(message);
    } 
 
    public Element getHeaderPart(String partName) {
        Element header = _dao.getHeader();
        if (header == null) return null;
 
        NodeList eltList = header.getElementsByTagName(partName);
        if (eltList.getLength() == 0) return null;
        else return (Element) eltList.item(0);
    } 
 
    public void setHeaderPart(String name, Element content) {
        Element header =  _dao.getHeader();
        if (header == null) {
            Document doc = DOMUtils.newDocument();
            header = doc.createElement("header");
            doc.appendChild(header);
        } 
        Element part = header.getOwnerDocument().createElement(name);
        header.appendChild(part);
        part.appendChild(header.getOwnerDocument().importNode(content, true));
        _dao.setHeader(header);
    } 
 
    public void setHeaderPart(String name, String content) {
        Element header =  _dao.getHeader();
        if (header == null) {
            Document doc = DOMUtils.newDocument();
            header = doc.createElement("header");
            doc.appendChild(header);
        } 
        Element part = header.getOwnerDocument().createElement(name);
        header.appendChild(part);
        part.setTextContent(content);
        _dao.setHeader(header);
    } 
 
    public void setMessage(Element msg) {
        _dao.setData(msg);
    } 
 
    public Element getMessage() {
        return _dao.getData();
    }