Example usage for org.dom4j Element add

List of usage examples for org.dom4j Element add

Introduction

In this page you can find the example usage for org.dom4j Element add.

Prototype

void add(Namespace namespace);

Source Link

Document

Adds the given Namespace to this element.

Usage

From source file:net.erdfelt.android.sdkfido.project.maven.MavenMultiSubGen.java

License:Apache License

@Override
public void generate(File outputFile) throws OutputProjectException {
    LOG.info("Generating: " + outputFile);

    Document pom = FilteredFileUtil.loadExpandedXml("maven-multi-sub.xml", props);

    if (needsAapt) {
        Document aapt = FilteredFileUtil.loadExpandedXml("plugin-exec-aapt.xml", props);

        Element plugins = (Element) pom.selectSingleNode("/project/build/plugins");
        if (plugins == null) {
            plugins = pom.getRootElement().element("build").addElement("plugins");
        }/*ww  w.  j  av  a  2 s .c om*/

        plugins.add(aapt.getRootElement());
    }

    FilteredFileUtil.write(pom, outputFile);
}

From source file:net.nikr.eve.jeveasset.io.local.update.Update.java

License:Open Source License

void setVersion(final File xml, final int newVersion) throws DocumentException {
    SAXReader xmlReader = new SAXReader();
    Document doc = xmlReader.read(xml);

    XPath xpathSelector = DocumentHelper.createXPath("/settings");
    List<?> results = xpathSelector.selectNodes(doc);
    for (Iterator<?> iter = results.iterator(); iter.hasNext();) {
        Element element = (Element) iter.next();
        Attribute attr = element.attribute("version");
        if (attr == null) {
            element.add(new DefaultAttribute("version", String.valueOf(newVersion)));
        } else {/*from  w  w w . ja va 2s. co m*/
            attr.setText(String.valueOf(newVersion));
        }
    }

    try {
        FileOutputStream fos = new FileOutputStream(xml);
        OutputFormat outformat = OutputFormat.createPrettyPrint();
        outformat.setEncoding("UTF-16");
        XMLWriter writer = new XMLWriter(fos, outformat);
        writer.write(doc);
        writer.flush();
    } catch (IOException ioe) {
        LOG.error("Failed to update the serttings.xml version number", ioe);
        throw new RuntimeException(ioe);
    }
}

From source file:net.sf.jguard.ext.authorization.manager.XmlAuthorizationManager.java

License:Open Source License

private void insertPermissionsAndInheritance(Element principalElement, RolePrincipal ppal) {
    Element permsRefElement = principalElement.addElement(PERMISSIONS_REF);
    Set perms = ppal.getPermissions();
    for (Object orphanedPerm : perms) {
        Permission perm = (Permission) orphanedPerm;
        Element permRef = permsRefElement.addElement(PERMISSION_REF);
        //add the name attribute
        Attribute idAttribute = new UserDataAttribute(new QName(ID));
        idAttribute.setValue("" + perm.getId());
        permRef.add(idAttribute);
    }//w  w  w . j av  a 2 s  .  co  m

    //role inheritance is only supported by RolePrincipal
    if (ppal.getDescendants().size() > 0) {
        Element descendants = principalElement.addElement(DESCENDANTS);

        //add the descendants of this role
        for (RolePrincipal o : ppal.getDescendants()) {
            Element principalRef = descendants.addElement(PRINCIPAL_REF);

            Attribute idAttribute = new UserDataAttribute(new QName(ID));
            idAttribute.setValue("" + o.getId());
            principalRef.add(idAttribute);
        }
    }
}

From source file:net.sf.kraken.muc.BaseMUCTransport.java

License:Open Source License

/**
 * Sends information about a room as a response to a service discovery request.
 *
 * @param to JID we will be sending the response to.
 * @param roomjid JID of the room info was requested about.
 * @param room A MUCTransportRoom object containing information to return as a response.
 *//*from www . j  av a 2  s .c  om*/
public void sendRoomInfo(JID to, JID roomjid, MUCTransportRoom room) {
    IQ request = getPendingRequest(to, roomjid, NameSpace.DISCO_INFO);
    if (request != null) {
        IQ result = IQ.createResultIQ(request);
        Element response = DocumentHelper.createElement(QName.get("query", NameSpace.DISCO_INFO));
        response.addElement("identity").addAttribute("category", "conference").addAttribute("type", "text")
                .addAttribute("name", room.getName());
        response.addElement("feature").addAttribute("var", NameSpace.MUC);
        response.addElement("feature").addAttribute("var", NameSpace.DISCO_INFO);
        response.addElement("feature").addAttribute("var", NameSpace.DISCO_ITEMS);
        if (room.getPassword_protected()) {
            response.addElement("feature").addAttribute("var", "muc_passwordprotected");
        }
        if (room.getHidden()) {
            response.addElement("feature").addAttribute("var", "muc_hidden");
        }
        if (room.getTemporary()) {
            response.addElement("feature").addAttribute("var", "muc_temporary");
        }
        if (room.getOpen()) {
            response.addElement("feature").addAttribute("var", "muc_open");
        }
        if (!room.getModerated()) {
            response.addElement("feature").addAttribute("var", "muc_unmoderated");
        }
        if (!room.getAnonymous()) {
            response.addElement("feature").addAttribute("var", "muc_nonanonymous");
        }
        Element form = DocumentHelper.createElement(QName.get("x", NameSpace.XDATA));
        form.addAttribute("type", "result");
        form.addElement("field").addAttribute("var", "FORM_TYPE").addAttribute("type", "hidden")
                .addElement("value").addCDATA("http://jabber.org/protocol/muc#roominfo");
        if (room.getContact() != null) {
            form.addElement("field").addAttribute("var", "muc#roominfo_contactjid")
                    .addAttribute("label", "Contact Addresses").addElement("value")
                    .addCDATA(room.getContact().toString());
        }
        if (room.getName() != null) {
            form.addElement("field").addAttribute("var", "muc#roominfo_description")
                    .addAttribute("label", "Short Description of Room").addElement("value")
                    .addCDATA(room.getName());
        }
        if (room.getLanguage() != null) {
            form.addElement("field").addAttribute("var", "muc#roominfo_lang")
                    .addAttribute("label", "Natural Language for Room Discussions").addElement("value")
                    .addCDATA(room.getLanguage());
        }
        if (room.getLog_location() != null) {
            form.addElement("field").addAttribute("var", "muc#roominfo_logs")
                    .addAttribute("label", "URL for Archived Discussion Logs").addElement("value")
                    .addCDATA(room.getLog_location());
        }
        if (room.getOccupant_count() != null) {
            form.addElement("field").addAttribute("var", "muc#roominfo_occupants")
                    .addAttribute("label", "Current Number of Occupants in Room").addElement("value")
                    .addCDATA(room.getOccupant_count().toString());
        }
        if (room.getTopic() != null) {
            form.addElement("field").addAttribute("var", "muc#roominfo_subject")
                    .addAttribute("label", "Current Subject or Discussion Topic in Room").addElement("value")
                    .addCDATA(room.getTopic());
        }
        response.add(form);
        result.setChildElement(response);
        this.sendPacket(result);
    }
}

From source file:net.sf.kraken.registration.RegistrationHandler.java

License:Open Source License

/**
 * Handles a IQ-register 'get' request, which is to be interpreted as a
 * request for a registration form template. The template will be prefilled
 * with data, if the requestee has a current registration with the gateway.
 *
 * @param packet the IQ-register 'get' stanza.
 * @throws UnauthorizedException if the user is not allowed to make use of the gateway.
 *///  w  ww .  j a  v a2  s.  c om
private void getRegistrationForm(IQ packet) throws UnauthorizedException {
    final JID from = packet.getFrom();
    final IQ result = IQ.createResultIQ(packet);

    // search for existing registrations
    String curUsername = null;
    String curPassword = null;
    String curNickname = null;
    Boolean registered = false;
    final Collection<Registration> registrations = RegistrationManager.getInstance().getRegistrations(from,
            parent.transportType);
    if (registrations.iterator().hasNext()) {
        Registration registration = registrations.iterator().next();
        curUsername = registration.getUsername();
        curPassword = registration.getPassword();
        curNickname = registration.getNickname();
        registered = true;
    }

    // Verify that the user is allowed to make use of the gateway.
    if (!registered && !parent.permissionManager.hasAccess(from)) {
        // User does not have permission to register with transport.
        // We want to allow them to change settings if they are already
        // registered.
        throw new UnauthorizedException(
                LocaleUtils.getLocalizedString("gateway.base.registrationdeniedbyacls", "kraken"));
    }

    // generate a template registration form.
    final Element response = DocumentHelper.createElement(QName.get("query", NameSpace.IQ_REGISTER));
    final DataForm form = new DataForm(DataForm.Type.form);
    form.addInstruction(parent.getTerminologyRegistration());

    final FormField usernameField = form.addField();
    usernameField.setLabel(parent.getTerminologyUsername());
    usernameField.setVariable("username");
    usernameField.setType(FormField.Type.text_single);
    if (curUsername != null) {
        usernameField.addValue(curUsername);
    }

    final FormField passwordField = form.addField();
    passwordField.setLabel(parent.getTerminologyPassword());
    passwordField.setVariable("password");
    passwordField.setType(FormField.Type.text_private);
    if (curPassword != null) {
        passwordField.addValue(curPassword);
    }

    final String nicknameTerm = parent.getTerminologyNickname();
    if (nicknameTerm != null) {
        FormField nicknameField = form.addField();
        nicknameField.setLabel(nicknameTerm);
        nicknameField.setVariable("nick");
        nicknameField.setType(FormField.Type.text_single);
        if (curNickname != null) {
            nicknameField.addValue(curNickname);
        }
    }

    response.add(form.getElement());
    response.addElement("instructions").addText(parent.getTerminologyRegistration());

    // prefill the template with existing data if a registration already
    // exists.
    if (registered) {
        response.addElement("registered");
        response.addElement("username").addText(curUsername);
        if (curPassword == null) {
            response.addElement("password");
        } else {
            response.addElement("password").addText(curPassword);
        }
        if (nicknameTerm != null) {
            if (curNickname == null) {
                response.addElement("nick");
            } else {
                response.addElement("nick").addText(curNickname);
            }
        }
    } else {
        response.addElement("username");
        response.addElement("password");
        if (nicknameTerm != null) {
            response.addElement("nick");
        }
    }

    // Add special indicator for rosterless gateway handling.
    response.addElement("x").addNamespace("", NameSpace.IQ_GATEWAY_REGISTER);

    result.setChildElement(response);

    parent.sendPacket(result);
}

From source file:net.sourceforge.sqlexplorer.dbproduct.Alias.java

License:Open Source License

/**
 * Describes this alias in XML; the result can be passed to the Alias(Element) constructor to refabricate it
 * /*from   www .  ja v  a2s .  c  o m*/
 * @return
 */
public Element describeAsXml() {
    DefaultElement root = new DefaultElement(ALIAS);
    root.addAttribute(AUTO_LOGON, Boolean.toString(autoLogon));
    root.addAttribute(CONNECT_AT_STARTUP, Boolean.toString(connectAtStartup));
    root.addAttribute(DRIVER_ID, driverId);
    root.addAttribute(HAS_NO_USER_NAME, Boolean.toString(hasNoUserName));
    root.addElement(NAME).setText(name);
    root.addElement(URL).setText(url);
    root.addElement(FOLDER_FILTER_EXPRESSION).setText(folderFilterExpression);
    root.addElement(NAME_FILTER_EXPRESSION).setText(nameFilterExpression);
    root.addElement(SCHEMA_FILTER_EXPRESSION).setText(schemaFilterExpression);
    Element usersElem = root.addElement(USERS);
    for (User user : users.values()) {
        // user.setPassword(ALIAS)
        usersElem.add(user.describeAsXml());
    }
    if (defaultUser != null) {
        root.addElement(DEFAULT_USER).setText(defaultUser.getUserName());
    }
    return root;
}

From source file:net.sourceforge.sqlexplorer.dbproduct.DriverManager.java

License:Open Source License

/**
 * Saves the drivers back to disk/*from  w w  w  .j a  v a  2  s  .c om*/
 * @throws ExplorerException
 */
public void saveDrivers() throws ExplorerException {
    Element root = new DefaultElement(DRIVERS);
    for (ManagedDriver driver : drivers.values())
        root.add(driver.describeAsXml());

    try {
        FileWriter writer = new FileWriter(new File(ApplicationFiles.USER_DRIVER_FILE_NAME));
        OutputFormat format = OutputFormat.createPrettyPrint();
        XMLWriter xmlWriter = new XMLWriter(writer, format);
        xmlWriter.write(root);
        writer.flush();
        writer.close();
    } catch (IOException e) {
        throw new ExplorerException(e);
    }
}

From source file:net.unicon.academus.apps.briefcase.migrate.BriefcaseMigrator.java

License:Open Source License

public static void main(String[] args) {

    System.out.println("Starting Briefcase portlet migration of data from Academus 1.5 " + " to Academus 1.6");

    if (args.length == 2) {
        try {/*w  w w .j  a  v a  2s.c o  m*/
            DataSource ds = new SimpleDataSource();

            SAXReader reader = new SAXReader();

            // replace the old urls with the new classpaths
            System.out.println("Updating the resource urls.");
            updateUrl(ds);
            updateSharedResourceUrls(ds);

            // replace the OWNER access type.
            System.out.println("Updating the accessTypes.");
            updateAccessType(ds);

            // set the uni_sequence table for the RdbmsAccessBroker Counter
            // and the FSA_Kernel_Sequencer
            updateSequencers(ds);

            // read the old config file
            // and correct the classpaths for all the access brokers.  
            Document oldDoc = reader.read(args[0]);

            DOMDocumentFactory dFac = new DOMDocumentFactory();

            // Get all access brokers
            List brokers = oldDoc.selectNodes("//access-broker");
            Element broker = null;

            // Change access brokers to point to alchemist instead of academus
            for (int i = 0; i < brokers.size(); i++) {
                broker = (Element) brokers.get(i);
                String implValue = broker.attributeValue("impl").replaceFirst("academus", "alchemist");
                broker.addAttribute("impl", implValue);
            }

            // Get the Access Broker under the personal Drive, and make sure it's a JIT broker
            Element targetsJitAccessBroker = (Element) ((Element) oldDoc.selectNodes(
                    "/briefcase/drive[@handle='personal']/access-broker[@impl='net.unicon.alchemist.access.jit.JitAccessBroker']")
                    .get(0)).detach();

            // Only enter this code if the personal drive section was successful selected
            if (targetsJitAccessBroker != null) {

                // Create new permissions element, mirroring targets element
                Element permissionsJitAccessBroker = (Element) targetsJitAccessBroker.clone();

                // Change handles
                targetsJitAccessBroker.addAttribute("handle", "personal-resourses-t");
                permissionsJitAccessBroker.addAttribute("handle", "personal-resourses-p");

                // Create new permissions access-broker
                Element permAccessBroker = dFac.createElement(new QName("access-broker"), 2);
                permAccessBroker.addAttribute("handle", "personal-jit");
                permAccessBroker.addAttribute("impl", PermissionsAccessBroker.class.getName());

                // Create new access element and add it to permAccessBroker
                Element permAccess = dFac.createElement(new QName("access"), 1);
                permAccess.addAttribute("impl", BriefcaseAccessType.class.getName());
                permAccessBroker.add(permAccess);

                // Create targets and permissions elements and add to the new permissions access-broker
                Element targets = permAccessBroker.addElement("targets");
                targets.add(targetsJitAccessBroker);

                Element permissions = permAccessBroker.addElement("permissions");
                permissions.add(permissionsJitAccessBroker);

                // Add new permissions access broker to the drive
                Element curDrive = (Element) oldDoc.selectNodes("/briefcase/drive[@handle='personal']").get(0);
                curDrive.add(permAccessBroker);

                //
                // Change targets internals
                //

                List targetsAccess = targets.selectNodes("access-broker/jit-rule/behavior/access");
                for (int i = 0; i < targetsAccess.size(); i++) {

                    // Add impl attribute with value of fully-qualified class name
                    ((Element) targetsAccess.get(i)).addAttribute("impl", DummyAccessType.class.getName());

                    // Get all child type elements and remove them
                    List types = ((Element) targetsAccess.get(i)).elements();
                    for (int j = 0; j < types.size(); j++) {
                        ((Element) types.get(j)).detach();
                    }

                    // Add a single dummy element
                    Element eType = dFac.createElement(new QName("type"), 2);
                    eType.addAttribute("value", "GRANT");
                    eType.addAttribute("handle", "DUMMY");

                    ((Element) targetsAccess.get(i)).add(eType);

                }

                // Add internal access broker's access element
                Element targetsIAccessBroker = (Element) (targets.selectNodes("access-broker/access-broker")
                        .get(0));
                Element targetsIAccess = dFac.createElement(new QName("access"), 1);
                targetsIAccess.addAttribute("impl", DummyAccessType.class.getName());
                targetsIAccessBroker.add(targetsIAccess);

                //
                // Change permissions internals
                //

                List permissionsAccess = permissions.selectNodes("access-broker/jit-rule/behavior/access");
                for (int i = 0; i < permissionsAccess.size(); i++) {
                    // Add impl attribute with value of fully-qualified class name
                    ((Element) permissionsAccess.get(i)).addAttribute("impl",
                            BriefcaseAccessType.class.getName());

                    // Get all child type elements and replace them
                    List types = ((Element) permissionsAccess.get(i)).elements();
                    for (int j = 0; j < types.size(); j++) {
                        Attribute value = ((Element) types.get(j)).attribute("value");
                        String text = value.getValue();
                        value.setValue("GRANT");

                        if (text.equals("0")) {
                            BriefcaseAccessType[] aTypes = BriefcaseAccessType.getInstances();
                            ((Element) types.get(j)).addAttribute("handle", aTypes[0].getName());

                            for (int k = 1; k < aTypes.length; k++) {
                                Element eType = dFac.createElement(new QName("type"), 2);
                                eType.addAttribute("value", "GRANT");
                                eType.addAttribute("handle", aTypes[k].getName());
                                ((Element) permissionsAccess.get(i)).add(eType);
                            }
                        } else {
                            ((Element) types.get(j)).addAttribute("handle",
                                    BriefcaseAccessType.getAccessType(Integer.parseInt(text)).getName());
                        }
                    }

                }

                // Change other elements in the permissions section
                List permissionsBehavior = permissions.selectNodes("access-broker/jit-rule/behavior");
                for (int i = 0; i < permissionsBehavior.size(); i++) {
                    Element trigger = (Element) ((Element) permissionsBehavior.get(i)).elements("trigger")
                            .get(0);
                    Element target = (Element) ((Element) permissionsBehavior.get(i)).elements("target").get(0);
                    Element creator = (Element) ((Element) permissionsBehavior.get(i)).elements("creator")
                            .get(0);

                    // Insert trigger text into target
                    target.addAttribute("type", "GROUP");
                    target.addText(trigger.getText());

                    // Remove current creator element
                    creator.detach();

                    // Add new current creator element
                    Element eCreator = dFac.createElement(new QName("creator"), 1);
                    eCreator.addAttribute("impl", DummyCreator.class.getName());
                    ((Element) permissionsBehavior.get(i)).add(eCreator);
                }

                // Change internal access broker's name
                Element permissionsIAccessBroker = (Element) (permissions
                        .selectNodes("access-broker/access-broker").get(0));
                permissionsIAccessBroker.addAttribute("handle", "personal-resources-p-i");

                // Add internal access broker's access element
                Element permissionsIAccess = dFac.createElement(new QName("access"), 1);
                permissionsIAccess.addAttribute("impl", BriefcaseAccessType.class.getName());
                permissionsIAccessBroker.add(permissionsIAccess);

            }

            List access = oldDoc.selectNodes("/briefcase/drive[@handle!='personal']//access");
            for (int i = 0; i < access.size(); i++) {

                // Add impl attribute with value of fully-qualified class name
                ((Element) access.get(i)).addAttribute("impl", BriefcaseAccessType.class.getName());

                List types = ((Element) access.get(i)).elements();
                for (int j = 0; j < types.size(); j++) {
                    Attribute value = ((Element) types.get(j)).attribute("value");
                    String text = value.getValue();
                    value.setValue("GRANT");

                    if (text.equals("0")) {
                        BriefcaseAccessType[] aTypes = BriefcaseAccessType.getInstances();
                        ((Element) types.get(j)).addAttribute("handle", aTypes[0].getName());

                        for (int k = 1; k < aTypes.length; k++) {
                            Element eType = dFac.createElement(new QName("type"), 2);
                            eType.addAttribute("value", "GRANT");
                            eType.addAttribute("handle", aTypes[k].getName());
                            ((Element) access.get(i)).add(eType);
                        }
                    } else {
                        ((Element) types.get(j)).addAttribute("handle",
                                BriefcaseAccessType.getAccessType(Integer.parseInt(text)).getName());
                    }
                }
            }

            // add impl attribute to specify the UserDirectory impl to user-attribute element
            List userAttr = oldDoc.selectNodes("//user-attribute");
            for (int i = 0; i < userAttr.size(); i++) {
                ((Element) userAttr.get(i)).addAttribute("impl",
                        "net.unicon.academus.apps.briefcase.UserAttributeDirectory");
            }

            //replace the resource factory urls  
            List entries = oldDoc
                    .selectNodes("/briefcase/drive[@handle!='personal']//access-broker/entry[@target!='']");
            for (int i = 0; i < entries.size(); i++) {
                ((Element) entries.get(i)).addAttribute("target", ((Element) entries.get(i))
                        .attributeValue("target").replaceAll("academus.resource.factory", "demetrius.fac"));
            }

            // add access element to specify the AccessType to the RdbmsAccessBroker
            brokers = oldDoc.selectNodes("/briefcase/drive[@handle!='personal']//access-broker[@impl='"
                    + RdbmsAccessBroker.class.getName() + "']");

            for (int i = 0; i < brokers.size(); i++) {
                broker = (Element) brokers.get(i);
                Element eType = dFac.createElement(new QName("access"), 1);
                eType.addAttribute("impl", BriefcaseAccessType.class.getName());
                broker.add(eType);
            }

            // add the civis address book information.
            Element drive = (Element) oldDoc.selectSingleNode("briefcase");
            drive.addComment("Civis implementation to be used to resolve usernames and group paths"
                    + " to academus users and groups. This should not require"
                    + " modification, as it utilized the Academus framework for gathering this"
                    + " information.");

            Element civis = dFac.createElement("civis");
            civis.addAttribute("id", "addressBook");
            civis.addAttribute("impl", "net.unicon.civis.fac.academus.AcademusCivisFactory");

            Element restrictor = dFac.createElement("restrictor");
            restrictor.addAttribute("impl", "net.unicon.civis.grouprestrictor.AcademusGroupRestrictor");
            civis.add(restrictor);

            drive.add(civis);

            File f = new File(args[1]);
            PrintWriter pw = new PrintWriter(new FileOutputStream(f));
            pw.write(oldDoc.asXML());
            pw.flush();
            pw.close();

            System.out.println(
                    "Done. Enjoy !! \n Remember to the use the migrated config file with the 1.6 deploy.");

        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        usage();
    }

}

From source file:net.unicon.toro.installer.tools.MergeConfiguration.java

License:Open Source License

private void addNode(Element source, Element replace, String xpath) {
    List list = replace.selectNodes("value");
    if (list == null)
        return;//  w  ww .j  a va 2 s .  c  om

    Element newContent = DocumentHelper.createElement("newContent");
    Comment prefixComment = DocumentHelper.createComment(CHANGE_START_COMMENT);
    Comment suffixComment = DocumentHelper.createComment(CHANGE_END_COMMENT);
    newContent.add(prefixComment);
    Iterator itr = list.iterator();
    while (itr.hasNext()) {
        Element value = (Element) itr.next();
        newContent.appendContent(value);
    }
    newContent.add(suffixComment);

    List sourceList = source.selectNodes(xpath);
    if (sourceList == null || sourceList.size() == 0) {
        throw new RuntimeException("xpath expression doesn't resolve to a node: " + xpath);
    }

    System.out.println("Xpath: " + xpath + " resolves to " + sourceList.size() + " nodes.");

    itr = sourceList.iterator();
    while (itr.hasNext()) {
        Element sourceEl = (Element) itr.next();
        System.out.println("Appending to xpath: " + sourceEl.getPath()); // + "newContent:\n" + newContent.asXML());
        sourceEl.appendContent(newContent);
    }
}

From source file:net.unicon.toro.installer.tools.MergeConfiguration.java

License:Open Source License

private void replaceElement(Element sourceEl, Element replacementElement) {
    if (!sourceEl.getName().equals(replacementElement.getName())) {
        throw new RuntimeException("replacement element must have the same name: " + sourceEl.getName()
                + " and " + replacementElement.getName() + " differ.");
    }// w ww. j a va2  s  .c o  m

    // remove all the existing
    sourceEl.attributes().clear();

    // remove all child elements
    sourceEl.elements().clear();

    // add all the new attributes
    sourceEl.appendAttributes(replacementElement);

    // add all the new child elements
    Iterator eItr = new ArrayList(replacementElement.elements()).iterator();
    while (eItr.hasNext()) {
        Element newEl = (Element) eItr.next();
        replacementElement.remove(newEl);
        sourceEl.add(newEl);
    }
}