Example usage for org.dom4j DocumentHelper createElement

List of usage examples for org.dom4j DocumentHelper createElement

Introduction

In this page you can find the example usage for org.dom4j DocumentHelper createElement.

Prototype

public static Element createElement(String name) 

Source Link

Usage

From source file:com.noterik.bart.fs.action.FlandersAction.java

License:Open Source License

private String processXml(String original, String flanders) {
    String xml = "";

    Map<String, String> values = new HashMap<String, String>();

    Document origdoc = null;//ww w. j  a v  a  2  s. c o  m
    Document flandoc = null;

    try {
        origdoc = DocumentHelper.parseText(original);
        flandoc = DocumentHelper.parseText(flanders);
    } catch (DocumentException e) {
        logger.error("", e);
    }

    Element origProp = (Element) origdoc.selectSingleNode("//properties");
    Iterator i = origProp.elementIterator();

    while (i.hasNext()) {
        Element prop = (Element) i.next();
        String name = prop.getName();
        String value = prop.getText();
        values.put(name, value);
    }

    logger.debug("\n flandProp = " + flandoc.asXML());

    Element flandProp = (Element) flandoc.selectSingleNode("/meta-data");
    Iterator j = flandProp.elementIterator();

    while (j.hasNext()) {
        Element prop = (Element) j.next();
        String name = prop.getName();
        String value = prop.getText();

        //For marin there metadata is leading
        if (values.containsKey("mount") && values.get("mount").toLowerCase().equals("marin")) {
            if (!values.containsKey(name)) {
                values.put(name, value);
            }
        } else {
            values.put(name, value);
        }
    }

    Element finalEl = DocumentHelper.createElement("fsxml");
    Element propsEl = finalEl.addElement("properties");

    Iterator<String> it = values.keySet().iterator();
    while (it.hasNext()) {
        String name = it.next();
        String value = values.get(name);
        propsEl.addElement(name).addText(value);
    }

    xml = finalEl.asXML();

    return xml;
}

From source file:com.noterik.bart.fs.fscommand.ResolutionMetaCommand.java

License:Open Source License

private Element createMeta(String input) {
    String basePath = "/springfield/smithers/data/";
    if (LazyHomer.isWindows()) {
        basePath = "c:\\springfield\\smithers\\data\\";
    }/*ww  w  .  ja va2 s . c  o m*/
    File srcFolder = new File(basePath + input);

    if (!srcFolder.exists())
        return null;
    if (!srcFolder.isDirectory())
        return null;

    File[] metafiles = srcFolder.listFiles(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            if (name.equals(".") || name.equals("..")) {
                return false;
            }
            if (name.toUpperCase().endsWith(".META")) {
                return true;
            }
            return false;
        }
    });

    Element metanode = DocumentHelper.createElement("resolutionmeta");

    // set the id and aim it to our original video
    metanode.addAttribute("id", "1");

    // create the properties and set them (this can be done easer?)
    Element p = DocumentHelper.createElement("properties");
    Element dataunits = DocumentHelper.createElement("dataunits");
    //Element availableinputs = DocumentHelper.createElement("inputs");

    String body = "<![CDATA[";
    String sep = "";
    body += "{";
    for (int i = 0; i < metafiles.length; i++) {
        File f = metafiles[i];
        Properties meta = readMetaFile(f);
        String filename = f.getName();
        String name = filename.substring(0, filename.lastIndexOf("."));
        if (meta.getProperty("startmeasurement") != null) {
            body += sep + "\"" + name + "\" : { \"name\" : \"" + meta.getProperty("name") + "\", \"unit\" : \""
                    + meta.getProperty("unit") + "\", \"startmeasurement\" : \""
                    + meta.getProperty("startmeasurement") + "\", \"endmeasurement\" : \""
                    + meta.getProperty("endmeasurement") + "\"}";
        } else {
            body += sep + "\"" + name + "\" : { \"name\" : \"" + meta.getProperty("name") + "\", \"unit\" : \""
                    + meta.getProperty("unit") + "\"}";
        }
        sep = ",";
    }
    body += "}";
    body += "]]>";

    dataunits.setText(body);

    body = "";
    sep = "";
    for (inputs val : inputs.values()) {
        body += sep + val;
        sep = ",";
    }

    //availableinputs.setText(body);
    //p.add(availableinputs);
    p.add(dataunits);

    // add the properties to the video node so it plays just that part.
    metanode.add(p);

    return metanode;
}

From source file:com.noterik.bart.fs.fscommand.ResolutionMetaCommand.java

License:Open Source License

private Element createMeta(String sbfFile, inputs input) {
    SBFReader sbfr = new SBFReader(sbfFile);

    Element metanode = DocumentHelper.createElement("resolutionmeta");

    // set the id and aim it to our original video
    metanode.addAttribute("id", "1");

    // create the properties and set them (this can be done easer?)
    Element p = DocumentHelper.createElement("properties");
    Element dataunits = DocumentHelper.createElement("dataunits");
    Element availableinputs = DocumentHelper.createElement("inputs");

    String body = "";
    SBFile dataFile = sbfr.getDataFile();
    int cols = (int) dataFile.getColumnCount();
    String sep = "";
    body += "{";/*from  www  .j  a va2  s .c o  m*/
    for (int i = 1; i < cols; i++) {
        body += sep + "\"" + input + "_" + Integer.toString(i) + "\" : { \"name\" : \""
                + dataFile.getDataColumns(i) + "\", \"unit\" : \"" + dataFile.getUnitColumns(i) + "\"}";
        sep = ",";
    }
    body += "}";

    sbfr = null;

    dataunits.setText(body);

    body = "";
    sep = "";
    for (inputs val : inputs.values()) {
        body += sep + val;
        sep = ",";
    }

    availableinputs.setText(body);
    p.add(availableinputs);
    p.add(dataunits);

    // add the properties to the video node so it plays just that part.
    metanode.add(p);

    return metanode;
}

From source file:com.noterik.bart.fs.ingest.IngestHandler.java

License:Open Source License

public String ingestVideo(String uri, String domain, String xml) {
    String response = null;//w  w  w  .  j  a v  a 2s .  c  om
    String origin = "";
    String destination = "";
    // get the settings file to see what to do with this video ingest
    String domIngest = "/domain/" + domain + "/settings/ingest";
    String ingest = PropertyHandler.getXMLfromProp(domIngest);
    // determine the path to the video file
    String fileName = XmlHelper.getPropertyValue(xml, XmlHelper.PROP_DATA);
    String extension = fileName.substring(fileName.lastIndexOf(".") + 1);
    origin = XmlHelper.getValueFromIngest(ingest, "/fsxml/properties/video/basedir") + uri + "/" + fileName;
    // where to store the video in the file system
    String url = XmlHelper.getPropertyValue(xml, XmlHelper.PROP_DESTINATION);
    String rawIndex = XmlHelper.getPropertyValue(xml, XmlHelper.PROP_RAW_INDEX);
    String dest = url + "/rawvideo/1";
    // whether to store in the old FS (b10) or the new one (use ftp)
    if (XmlHelper.useFtp(ingest, "video")) {
        String backupMount = null;
        String mount = null;

        String collection = XmlHelper.getPropertyValue(xml, XmlHelper.PROP_COLLECTION);

        String offPath = "/fsxml/properties/video/ftp/offset";
        String servPath = "/fsxml/properties/video/ftp/servers";
        String prefPath = "/fsxml/properties/video/ftp/prefix";
        String sufPath = "/fsxml/properties/video/ftp/suffix";
        String mtnPath = "/fsxml/properties/video/ftp/mount";

        String offset = XmlHelper.getValueFromIngest(ingest, offPath);
        String servers = XmlHelper.getValueFromIngest(ingest, servPath);
        String prefix = XmlHelper.getValueFromIngest(ingest, prefPath);
        String suffix = XmlHelper.getValueFromIngest(ingest, sufPath);
        String mountprf = XmlHelper.getValueFromIngest(ingest, mtnPath);
        int servs = Integer.valueOf(servers);
        int offs = Integer.valueOf(offset);

        if (extension.toLowerCase().equals("flv")) {
            dest = url + "/rawvideo/1";
        } else {
            dest = url + "/rawvideo/2";
        }
        // if the rawindex is specified in the request xml, put the video at
        // this rawvideo index
        if (rawIndex != null) {
            dest = rawIndex.equals("") ? dest : url + "/rawvideo/" + rawIndex;
        }
        logger.debug("Copying file to new FS (using FTP) into: " + dest + " rawindex(" + rawIndex + ")");
        int sid = getFTPServerIdForCollectionVideo(url, collection, servs, offs);
        if (sid != -1) {
            int bid = getBackupFTPServerId(sid, servs, offs);
            String sHostBase = prefix + sid;
            String bHostBase = prefix + bid;
            String ftpServer = sHostBase + suffix;
            String backupFtpServer = bHostBase + suffix;

            logger.debug("FTP SERVER: " + ftpServer);
            logger.debug("BACKUP FTP SERVER: " + backupFtpServer);
            logger.debug("INPUT FILE: " + origin);
            logger.debug("DESTINATION: " + dest);
            if (FtpHelper.sendFileWithFtp(origin, dest, ftpServer, sHostBase, sHostBase, false)) {
                mount = mountprf + sid;
            }
            if (FtpHelper.sendFileWithFtp(origin, dest, backupFtpServer, bHostBase, bHostBase, true)) {
                backupMount = mountprf + bid;
            }
            if (mount == null && backupMount == null) {
                response = FSXMLBuilder.getErrorMessage(
                        "500", "Could not transfer the ingest file to the FS", "The file: " + origin
                                + " could not be sent to either: " + sHostBase + " or " + bHostBase,
                        "http://teamelements.noterik.com/team");
            }
        } else {
            response = FSXMLBuilder.getErrorMessage("500", "Invalid destination URL parameter",
                    "The destination URL: " + url + " is invalid", "http://teamelements.noterik.com/team");
        }
        if (response == null) {
            logger.debug("response was null, properties will be set now !!");

            String properties = XmlHelper.getPropsFromXml(xml);
            String type = "rawvideo";
            if (mount != null || backupMount != null) {
                String m = mount;
                if (backupMount != null) {
                    m = m == null ? backupMount : m + "," + backupMount;
                }
                properties = XmlHelper.setMountProperty(properties, m);
            }
            logger.debug("xml before Flanders is: " + properties);
            // update the properties with information from flanders
            properties = FlandersHelper.processRaw(dest, properties);
            logger.debug("xml after Flanders is: " + properties);
            // add the properties to data base
            PropertyHandler.saveProperties(dest, type, properties);
            response = FSXMLBuilder.getStatusMessage("The file was succesfully ingested into the FS", "", "");
        } else {
            logger.error(response);
        }

    } else {
        String transPath = "/fsxml/properties/transcode";
        String transcode = XmlHelper.getValueFromIngest(ingest, transPath);

        logger.debug("Copying file to FS on b10 (old file system)");
        destination = GlobalConfig.instance().getIngestBaseDir() + dest + "/raw." + extension;
        if (!FileHelper.copyFile(origin, destination)) {
            response = FSXMLBuilder.getErrorMessage("500",
                    "Could not transfer the ingest file to the old (b10) FS",
                    "The file: " + origin + " could not be sent to the old (b10) FS",
                    "http://teamelements.noterik.com/team");
        } else {
            // file was copied successfully, now setting properties
            String type = "rawvideo";

            String properties = XmlHelper.getPropsFromXml(xml);
            logger.debug("xml before Flanders is: " + properties);
            // update the properties with information from flanders
            properties = FlandersHelper.processRaw(dest, properties);
            logger.debug("xml after Flanders is: " + properties);
            PropertyHandler.saveProperties(dest, type, properties);
        }
        // creating unhappy files
        if (transcode.equals("true")) {
            String type = "rawvideo";
            List<Element> elems = XmlHelper.getRaws(ingest, "video");
            if (elems.size() != 0) {
                Iterator<Element> it = elems.iterator();
                Element elem = null;
                while (it.hasNext()) {
                    elem = it.next();
                    String id = elem.attributeValue("id");
                    Element propsElem = (Element) elem.selectSingleNode("/properties");
                    Element fsxml = DocumentHelper.createElement("fsxml");
                    fsxml.add((Element) propsElem.clone());
                    String props = fsxml.asXML();
                    url = uri + "/rawvideo/" + id;

                    PropertyHandler.saveProperties(url, type, props);
                }
            }
            String newUrl = url.substring(1);
            String TEFurl = "http://cw2.noterik.com:10001/domain/emails/fsorders";
            String finalUrl = TEFurl + "?res=" + newUrl;
            HttpHelper.sendRequest("GET", finalUrl, null, null);
        }
    }

    return response;
}

From source file:com.noterik.bart.fs.ingest.IngestHandler.java

License:Open Source License

public String ingestImage(String uri, String domain, String xml) {
    logger.debug("Processing image ingest...");

    String domIngest = "/domain/" + domain + "/settings/ingest";
    String ingest = PropertyHandler.getXMLfromProp(domIngest);
    String origin = "";
    String fileName = XmlHelper.getPropertyValue(xml, XmlHelper.PROP_DATA);
    String extension = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
    origin = XmlHelper.getValueFromIngest(ingest, "/fsxml/properties/image/basedir") + uri + "/" + fileName;
    String url = XmlHelper.getPropertyValue(xml, XmlHelper.PROP_DESTINATION);
    String dest = url + "/rawimage/1";

    String response = null;/*from  www  .ja  v a 2 s.  com*/
    String type = "rawimage";

    String imagePath = "";
    String prefix = "";
    String suffix = "";
    String user = "";
    String pass = "";
    String server = "";
    String backImagePath = "";
    String backServer = "";
    String backUser = "";
    String backPass = "";
    String mount = null;
    String backMount = null;

    boolean useFtp = XmlHelper.useFtp(ingest, "image");

    if (useFtp) {
        String prefixPath = "/fsxml/properties/image/ftp/prefix";
        String suffixPath = "/fsxml/properties/image/ftp/suffix";
        String userPath = "/fsxml/properties/image/ftp/user";
        String passPath = "/fsxml/properties/image/ftp/pass";

        prefix = XmlHelper.getValueFromIngest(ingest, prefixPath);
        suffix = XmlHelper.getValueFromIngest(ingest, suffixPath);
        user = XmlHelper.getValueFromIngest(ingest, userPath) + "1";
        pass = XmlHelper.getValueFromIngest(ingest, passPath) + "1";
        imagePath = XmlHelper.getValueFromIngest(ingest, "/fsxml/properties/image/ftp/path") + "1";

        server = prefix + "1" + suffix;
        backServer = prefix + "2" + suffix;

        backUser = XmlHelper.getValueFromIngest(ingest, userPath) + "2";
        backPass = XmlHelper.getValueFromIngest(ingest, passPath) + "2";
        backImagePath = XmlHelper.getValueFromIngest(ingest, "/fsxml/properties/image/ftp/path") + "2";

    } else {
        imagePath = XmlHelper.getValueFromIngest(ingest, "/fsxml/properties/image/basedir");
    }
    String newDest = imagePath + dest;
    String backNewDest = backImagePath + dest;

    List<Element> elems = XmlHelper.getRaws(ingest, "image");
    logger.debug("NUMBER OF RAWS: " + elems.size());
    if (elems.size() != 0) {
        Iterator<Element> it = elems.iterator();
        while (it.hasNext()) {
            Element elem = (Element) it.next().clone();
            String id = elem.attributeValue("id");
            String thumbDest = url + "/rawimage/" + id;
            logger.debug("ELEMENT FOUND:\n\n" + elem.asXML());
            Element propsElem = (Element) elem.selectSingleNode("./properties");
            logger.debug("PROPS ELEMENT:\n" + propsElem.asXML());
            if (propsElem != null) {
                String width = propsElem.selectSingleNode("./width").getText();
                String heigth = propsElem.selectSingleNode("./height").getText();
                int tWidth = Integer.valueOf(width);
                int tHeight = Integer.valueOf(heigth);
                String onlyName = fileName.substring(0, fileName.indexOf("."));
                String thumbLocation = XmlHelper.getValueFromIngest(ingest, "/fsxml/properties/image/basedir")
                        + uri + "/thumb" + onlyName + ".jpg";
                if (createThumb(tWidth, tHeight, origin, thumbLocation)) {
                    Element fsxml = DocumentHelper.createElement("fsxml");
                    fsxml.add((Element) propsElem.clone());
                    if (useFtp) {

                        //send to images1

                        String thumbNewDest = imagePath + thumbDest;
                        logger.debug("FTP HOST: " + server);
                        logger.debug("INPUT FILE: " + thumbLocation);
                        logger.debug("DESTINATION: " + thumbNewDest);
                        if (FtpHelper.sendFileWithFtp(thumbLocation, thumbNewDest, server, user, pass, false)) {
                            mount = "images1";
                        }

                        //send to images2
                        String backThumbDest = backImagePath + thumbDest;
                        logger.debug("FTP HOST: " + backServer);
                        logger.debug("INPUT FILE: " + thumbLocation);
                        logger.debug("DESTINATION: " + backThumbDest);
                        if (FtpHelper.sendFileWithFtp(thumbLocation, backThumbDest, backServer, backUser,
                                backPass, true)) {
                            backMount = "images2";
                        }
                        String props = fsxml.asXML();
                        if (mount != null || backMount != null) {
                            String m = mount;
                            if (backMount != null) {
                                m = m == null ? backMount : m + "," + backMount;
                            }
                            props = XmlHelper.setMountProperty(props, m);
                        }
                        PropertyHandler.saveProperties(thumbDest, type, props);
                    } else {
                        String thumbNewDest = imagePath + thumbDest;
                        if (!FileHelper.copyFile(thumbLocation, thumbNewDest)) {
                            response = FSXMLBuilder.getErrorMessage("500",
                                    "Could not transfer the ingest file to the old (b10) FS",
                                    "The file: " + origin + " could not be sent to the old (b10) FS",
                                    "http://teamelements.noterik.com/team");
                        } else {
                            String props = fsxml.asXML();
                            PropertyHandler.saveProperties(thumbDest, type, props);
                        }
                    }
                } else {
                    logger.error("There was an error creating thumbnail " + id);
                }
            } else {
                logger.error("The ingest settings xml is not properly configured");
            }
        }
    }
    if (useFtp) {
        //send to images1
        logger.debug("FTP HOST: " + server);
        logger.debug("INPUT FILE: " + origin);
        logger.debug("DESTINATION: " + newDest);
        if (FtpHelper.sendFileWithFtp(origin, newDest, server, user, pass, false)) {
            mount = "images1";
        }

        //send to images2
        logger.debug("FTP HOST: " + backServer);
        logger.debug("INPUT FILE: " + origin);
        logger.debug("DESTINATION: " + backNewDest);
        if (FtpHelper.sendFileWithFtp(origin, backNewDest, backServer, backUser, backPass, true)) {
            backMount = "images2";
        }
        String props = "<fsxml>" + "<properties>" + "<extension>" + extension + "</extension></properties>"
                + "</fsxml>";
        if (mount != null || backMount != null) {
            String m = mount;
            if (backMount != null) {
                m = m == null ? backMount : m + "," + backMount;
            }
            props = XmlHelper.setMountProperty(props, m);
        }
        PropertyHandler.saveProperties(dest, type, props);

    } else {
        if (!FileHelper.copyFile(origin, newDest)) {
            response = FSXMLBuilder.getErrorMessage("500",
                    "Could not transfer the ingest file to the old (b10) FS",
                    "The file: " + origin + " could not be sent to the old (b10) FS",
                    "http://teamelements.noterik.com/team");
        } else {
            String prop = "<fsxml>" + "<properties>" + "<extension>" + extension + "</extension>"
                    + "</properties>" + "</fsxml>";
            PropertyHandler.saveProperties(dest, type, prop);
        }

    }

    return response;
}

From source file:com.noterik.bart.fs.legacy.tools.FlandersHelper.java

License:Open Source License

private static String processXml(String original, String flanders) {
    String xml = "";

    Map<String, String> values = new HashMap<String, String>();

    Document origdoc = null;//from   w ww.j  a  v a2s.  co m
    Document flandoc = null;

    try {
        origdoc = DocumentHelper.parseText(original);
        flandoc = DocumentHelper.parseText(flanders);
    } catch (DocumentException e) {
        LOG.error("", e);
    }

    Element origProp = (Element) origdoc.selectSingleNode("//properties");
    Iterator i = origProp.elementIterator();

    while (i.hasNext()) {
        Element prop = (Element) i.next();
        String name = prop.getName();
        String value = prop.getText();
        values.put(name, value);
    }

    LOG.debug("\n flandProp = " + flandoc.asXML());

    Element flandProp = (Element) flandoc.selectSingleNode("/meta-data");
    Iterator j = flandProp.elementIterator();

    while (j.hasNext()) {
        Element prop = (Element) j.next();
        String name = prop.getName();
        String value = prop.getText();
        values.put(name, value);
    }

    Element finalEl = DocumentHelper.createElement("fsxml");
    Element propsEl = finalEl.addElement("properties");

    Iterator<String> it = values.keySet().iterator();
    while (it.hasNext()) {
        String name = it.next();
        String value = values.get(name);
        propsEl.addElement(name).addText(value);
    }

    xml = finalEl.asXML();

    return xml;
}

From source file:com.noterik.bart.fs.legacy.tools.XmlHelper.java

License:Open Source License

/**
 * This function returns a Document with the value of the property set by
 * path//from   w  w w.  j  a v a2 s  .  com
 *
 * @param xml
 *            String containing the property file
 * @param path
 *            The path for the desired value
 * @return Document with the value of the property
 */
public static Document getValueOfProperty(String xml, String path) {
    String xpath = "/fsxml/" + path;
    Document doc = null;
    try {
        doc = DocumentHelper.parseText(xml);
    } catch (DocumentException e) {
        e.printStackTrace();
    }
    Element elem = (Element) doc.selectSingleNode(xpath).clone();
    Document newDoc = DocumentHelper.createDocument();
    Element root = DocumentHelper.createElement("fsxml");
    newDoc.setRootElement(root);
    Element fsxml = (Element) newDoc.selectSingleNode("/fsxml");
    fsxml.add(elem);
    return newDoc;
}

From source file:com.poka.util.XmlSax.java

public Document load(String f, boolean isHiberConfig) {
    Document document = null;/*  ww w. ja  v a  2s  .  co  m*/
    try {
        SAXReader saxReader = new SAXReader();
        //saxReader.setValidation(false);  
        //saxReader.setFeature("http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd", false);              
        //document = saxReader.read(f); //?XML,document
        if (isHiberConfig) {
            saxReader.setEntityResolver(new EntityResolver() {
                @Override
                public InputSource resolveEntity(String publicId, String systemId)
                        throws SAXException, IOException {
                    // TODO Auto-generated method stub
                    InputSource is = new InputSource(this.getClass().getClassLoader()
                            .getResourceAsStream("com/poka/images/hibernate-configuration-3.0.dtd"));
                    is.setPublicId(publicId);
                    is.setSystemId(systemId);
                    return is;
                }
            });
            saxReader.setValidation(true);
        }
        File tFile = new File(f);
        if (!tFile.exists() && !isHiberConfig) {
            document = DocumentHelper.createDocument();
            //    document.addDocType("hibernate-configuration", "-//Hibernate/Hibernate Configuration DTD 3.0//EN", "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd");

            // 
            Element root = DocumentHelper.createElement("root");
            document.setRootElement(root);
        } else {
            document = saxReader.read(tFile);
        }

    } catch (DocumentException ex) {
    }
    return document;
}

From source file:com.pureinfo.dolphin.mapping.PropertyRef.java

License:Open Source License

/**
 * @see com.pureinfo.force.xml.IXMLSupporter#toXMLElement(org.dom4j.Element)
 *//*  www. j av  a2 s  .  c om*/
public void toXMLElement(Element _element) throws PureException {
    _element.addAttribute("type", m_sType);
    _element.addAttribute("key", m_sKey);
    _element.addAttribute("locator", m_sLocator);

    //to export indexes
    Element ele;
    for (int i = 1; i < m_indexes.length; i++) {
        ele = DocumentHelper.createElement("index");
        m_indexes[i].toXMLElement(ele);
        _element.add(ele);
    }
}

From source file:com.pureinfo.srm.config.affirm.domain.AffirmMgrImpl.java

License:Open Source License

public void store() throws PureException {
    if (!isLoaded())
        return;/*from  ww w .  java2s  . c  o m*/
    synchronized (this) {
        Element root = DocumentHelper.createElement(ELEMENT_AFFIRMS);
        m_affirm.toXMLElement(root);
        String sFileName = ClassResourceUtil.mapFullPath(DATA_FILENAME, true);
        try {
            new XMLWriter(new FileOutputStream(sFileName), OutputFormat.createPrettyPrint())
                    .write(DocumentHelper.createDocument(root));
        } catch (Exception ex) {
            throw new PureException(PureException.UNKNOWN, "", ex);
        }
    }
}