Example usage for org.jdom2 Element clone

List of usage examples for org.jdom2 Element clone

Introduction

In this page you can find the example usage for org.jdom2 Element clone.

Prototype

@Override
public Element clone() 

Source Link

Document

This returns a deep clone of this element.

Usage

From source file:site.util.EvXmlUtil.java

License:BSD License

public static String prettyPrint(Element e) {
    try {/*w  ww . j a va 2  s.c  om*/
        //TODO not sure if this works
        Document doc = new Document((Element) e.clone()); //need to clone?
        return xmlToString(doc);
    } catch (Exception e1) {
        e1.printStackTrace();
        return null;
    }
    /*      
                  
                  
          StringBuffer b=new StringBuffer();
          prettyPrint(e, b);
          return b.toString();*/
}

From source file:site.util.EvXmlUtil.java

License:BSD License

/**
 * Merge two XML-documents//from www .j ava 2s . c o m
 * @param to
 * @param from
 */
public static void mergeXML(Element to, Element from) {
    //For every element to be added
    for (Object o : from.getChildren()) {
        Element frome = (Element) o;

        //Find matching element in destination
        Element match = null;
        for (Object o2 : to.getChildren()) {
            Element toe = (Element) o2;
            if (elementsEqual(frome, toe)) {
                match = toe;
                break;
            }
        }

        //Add content
        if (match == null)
            to.addContent((Element) frome.clone());
        else
            mergeXML(match, frome);
    }
}