private void extendElement(Element base, Element elem) {
        for (Iterator it = elem.attributeIterator(); it.hasNext();) {
            Attribute attr = (Attribute) it.next();
            String name = attr.getName();
            String value = attr.getValue();
            Attribute baseAttr = base.attribute(name);
            if (baseAttr == null) {
                base.addAttribute(name, value);
            } else {
                baseAttr.setValue(value);
            }
        }
        if (elem.isTextOnly()) {
            base.setText(elem.getText());
        } else {
            for (Iterator it = elem.elementIterator(); it.hasNext();) {
                Element e = (Element) it.next();
                String name = e.getName();
                if (dtd != null) {
                    ElementDeclare elemDecl = dtd.getElementDeclare(base.getName());
                    if (elemDecl != null && elemDecl.multipleAllow(name)) {
                        base.add(e.createCopy());
                        continue;
                    }
                }
                Element baseElement = base.element(name);
                if (baseElement == null) {
                    baseElement = e.createCopy();
                    base.add(baseElement);
                }
                extendElement(baseElement, e);
            }
        }
    }